⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynamicform.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<Script Runat="Server">

Sub Page_Load
  Dim intCounter As Integer

  If Not IsPostBack Then
    ViewState( "ProductFieldCount" ) = 1
  ElseIf ViewState( "ProductFieldCount" ) > 1 Then
    For intCounter = 2 To ViewState( "ProductFieldCount" )
      AddProductField( intCounter )
    Next
  End If
End Sub

Sub AddProductFieldCount( s As Object, e As EventArgs )
  ViewState( "ProductFieldCount" ) += 1
  AddProductField( ViewState( "ProductFieldCount" ) )
End Sub

Sub AddProductField( strFieldNum As String )
  Dim litLabel As LiteralControl
  Dim txtTextBox As TextBox

  ' Add Literal Control
  litLabel = New LiteralControl
  litLabel.Text = "<p><b>Product " & strFieldNum & ":</b> "
  plhProductFields.Controls.Add( litLabel )

  ' Add TextBox Control
  txtTextBox = New TextBox
  txtTextBox.ID = "txtProduct" & strFieldNum
  plhProductFields.Controls.Add( txtTextBox )
End Sub

Sub btnSubmit_Click( s As Object, e As EventArgs )
  Response.Redirect( "ThankYou.aspx" )
End Sub

</Script>

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

<form Runat="Server">

<b>Customer Name:</b>
<asp:TextBox
  ID="txtCustomer"
  Runat="Server" />

<p>
<div style="background-color: yellow;padding:10px">

<b>Product 1:</b>
<asp:TextBox
  ID="txtProduct1"
  Runat="Server" />

<asp:PlaceHolder
  id="plhProductFields"
  Runat="Server" />

</div>

<p>
<asp:Button
  Text="Add Product Field"
  OnClick="AddProductFieldCount"
  Runat="Server" />

<asp:Button
  id="btnSubmit"
  Text="Submit Complete Order"
  OnClick="btnSubmit_Click"
  Runat="Server" />

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

⌨️ 快捷键说明

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