ASP.NET面板回发后返回到某个面板

  • 本文关键字:返回 NET ASP c# asp.net vb.net
  • 更新时间 :
  • 英文 :

// the buttons act like a panel tab*
<asp:button ID=Button1> = hide the panel2, show the panel1 
<asp:button ID=Button2> = hide the panel1, show the panel2

<asp:panel ID: panel1>
Contents of Panel 1. This is the default
</asp:panel>

<asp:panel ID: panel2>
Contents of Panel 2
<asp:button ID=Save> *response redirect to same page 
</asp:panel>

页面默认视图为Panel1

当我点击保存按钮时,我如何在回发后保持对Panel2的视图?一直返回到Panel1视图

任何帮助/提示都是感激的。谢谢你!

试试这个代码…

<asp:Button runat="server" ID="Button1" Text="Button1" OnClick="Button1_Click" />
<%--= hide the panel2, show the panel1 --%>
<asp:Button runat="server" ID="Button2" Text="Button2" OnClick="Button2_Click" />
<%--= hide the panel1, show the panel2--%>
<asp:Panel runat="server" ID="panel1">
Contents of Panel 1. This is the default
</asp:Panel>
<asp:Panel runat="server" ID="panel2">
Contents of Panel 2
<asp:Button runat="server" Text="Save" ID="Save"  OnClick="Save_Click"/>
</asp:Panel>

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
panel1.Visible = true;
panel2.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
panel1.Visible = true;
panel2.Visible = false;
}
protected void Button2_Click(object sender, EventArgs e)
{
panel1.Visible = false;
panel2.Visible = true;
}
protected void Save_Click(object sender, EventArgs e)
{
panel1.Visible = false;
panel2.Visible = true;
}

最新更新