📄 dynamicform.aspx
字号:
<%@ Page Language="C#"%>
<script runat=server>
void Page_Load(Object sender , EventArgs e)
{
if (! IsPostBack )
ViewState[ "ProductFieldCount" ] = 1;
else
for ( int intCounter = 2 ; intCounter <= (int)ViewState ["ProductFieldCount"]; intCounter++)
AddProductField( intCounter.ToString() );
}
void AddProductFieldCount( object s, EventArgs e ) {
ViewState[ "ProductFieldCount" ] = (int)ViewState[ "ProductFieldCount" ] + 1;
AddProductField( ViewState[ "ProductFieldCount" ].ToString() );
}
void AddProductField( string strFieldNum ) {
LiteralControl litLabel;
TextBox txtTextBox;
// 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 );
}
void btnSubmit_Click( object s, EventArgs e ) {
Response.Redirect( "ThankYou.aspx" );
}
</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 + -