panelmultipage.aspx

来自「asp.net技术内幕的书配源码」· ASPX 代码 · 共 139 行

ASPX
139
字号
<%@ Page Language="C#"%>

<script runat="server">

void Page_Load( Object s, EventArgs e ) 
{
  if (! IsPostBack ) {
    ViewState[ "CurrentPage" ] = 1;
  }
}

void btnNextPage_Click( object s, EventArgs e ) {
   Panel pnlPanel;
   string strPanelName;

  // Hide Previous Panel
  strPanelName = "pnlForm" + ViewState[ "CurrentPage" ];
  pnlPanel = (Panel)FindControl( strPanelName );
  pnlPanel.Visible = false;

  // Show Current Panel
  int currentPage = (int)ViewState["CurrentPage"];
  currentPage+=1;
  ViewState["CurrentPage"] = currentPage;
  strPanelName = "pnlForm" + ViewState[ "CurrentPage" ];
  pnlPanel = (Panel)FindControl( strPanelName );
  pnlPanel.Visible = true;
}

void btnPrevPage_Click( object s, EventArgs e ) {
   Panel pnlPanel;
   string strPanelName;

  // Hide Current Panel
  strPanelName = "pnlForm" + ViewState[ "CurrentPage" ];
  pnlPanel = (Panel)FindControl( strPanelName );
  pnlPanel.Visible = false;

  // Show Previous Panel
  int currentPage = (int)ViewState["CurrentPage"];
  currentPage-=1;
  ViewState["CurrentPage"] = currentPage;
  strPanelName = "pnlForm" + ViewState[ "CurrentPage" ];
  pnlPanel = (Panel)FindControl( strPanelName );
  pnlPanel.Visible = true;
}

void btnFinish_Click( object s, EventArgs e ) {
  pnlForm3.Visible = false;
  pnlForm4.Visible = true;
  lblSummary.Text = "<h2>You entered:</h2>";
  lblSummary.Text += "<li> First Name=" + txtFirstname.Text;
  lblSummary.Text += "<li> Last Name=" + txtLastname.Text;
  lblSummary.Text += "<li> Color=" + txtFavColor.Text;
  lblSummary.Text += "<li> Philosopher=" + radlFavPhilosopher.SelectedItem.Text;
}

</Script>

<html>
<head><title>PanelMultiPage.aspx</title></head>
<body>

<form Runat="Server">

<asp:Panel ID="pnlForm1" Runat="Server">

<h3>Page <%=ViewState[ "CurrentPage" ]%> of 3</h3>
<hr>
First Name:
<asp:TextBox
  ID="txtFirstname"
  Runat="Server" />
<p>
Last Name:
<asp:TextBox
  ID="txtLastname"
  Runat="Server" />
<hr>
<asp:Button
  Text="Next Page >>"
  OnClick="btnNextPage_Click"
  Runat="Server" />

</asp:Panel>
<asp:Panel ID="pnlForm2" Runat="Server" Visible="False">

<h3>Page <%=ViewState[ "CurrentPage" ]%> of 3</h3>
<hr>
Favorite Color:
<asp:TextBox
  ID="txtFavColor"
  Runat="Server" />
<hr>
<asp:Button
  Text="<< Prev Page"
  OnClick="btnPrevPage_Click"
  Runat="Server" />
<asp:Button
  Text="Next Page >>"
  OnClick="btnNextPage_Click"
  Runat="Server" />

</asp:Panel>
<asp:Panel ID="pnlForm3" Runat="Server" Visible="False">

<h3>Page <%=ViewState[ "CurrentPage" ]%> of 3</h3>
<hr>
Favorite Philosopher:
<asp:RadioButtonList
  ID="radlFavPhilosopher"
  Runat="Server">
  <asp:ListItem Text="Frege" Selected="True"/>
  <asp:ListItem Text="Russell" />
  <asp:ListItem Text="Carnap" />
</asp:RadioButtonList>
<hr>
<asp:Button
  Text="<< Prev Page"
  OnClick="btnPrevPage_Click"
  Runat="Server" />
<asp:Button
  Text="Finish"
  OnClick="btnFinish_Click"
  Runat="Server" />

</asp:Panel>
<asp:Panel ID="pnlForm4" Runat="Server" Visible="False">

<asp:Label
  ID="lblSummary"
  Runat="Server"/>

</asp:Panel>

</form>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?