panelmultipage.aspx

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

ASPX
132
字号
<Script Runat="Server">

Sub Page_Load
  If Not IsPostBack Then
    ViewState( "CurrentPage" ) = 1
  End If
End Sub

Sub btnNextPage_Click( s As Object, e As EventArgs )
  Dim pnlPanel As Panel
  Dim strPanelName AS String

  ' Hide Previous Panel
  strPanelName = "pnlForm" & ViewState( "CurrentPage" )
  pnlPanel = FindControl( strPanelName )
  pnlPanel.Visible = False

  ' Show Current Panel
  ViewState( "CurrentPage" ) += 1
  strPanelName = "pnlForm" & ViewState( "CurrentPage" )
  pnlPanel = FindControl( strPanelName )
  pnlPanel.Visible = True
End Sub

Sub btnPrevPage_Click( s As Object, e As EventArgs )
  Dim pnlPanel As Panel
  Dim strPanelName AS String

  ' Hide Current Panel
  strPanelName = "pnlForm" & ViewState( "CurrentPage" )
  pnlPanel = FindControl( strPanelName )
  pnlPanel.Visible = False

  ' Show Previous Panel
  ViewState( "CurrentPage" ) -= 1
  strPanelName = "pnlForm" & ViewState( "CurrentPage" )
  pnlPanel = FindControl( strPanelName )
  pnlPanel.Visible = True
End Sub

Sub btnFinish_Click( s As Object, e As EventArgs )
  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
End Sub

</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 + -
显示快捷键?