We are familiar with the dynamic writing of HTML tag controls, and this is no longer stated here. This article focuses on how to dynamically write server-side controls, and on the server side to get the various properties of the server-side controls that are written dynamically when the page is postback to the server side.
Here, I'm going to illustrate the application with a demo.
Demand:
1. Users enter a numeric value on the UI (for example: 5), and the system dynamically loads the URL address input field for the user;
2. User input URL address content needs to be authenticated by URL format;
3. After the user submits the input content, the system gives the result of the submission
The design is as follows:
1. CSS style settings:
The following are the referenced contents:
Copy Code code as follows:
<style type= "Text/css" >
. Item
{
margin:10px;
Border-bottom:solid 1px #CCC;
}
. item2
{
margin:5px;
}
. Input
{
width:200px;
}
</style>
2. Front page code:
Copy Code code as follows:
<div>
<div class= "Item" >
Please input a number:
<asp:textbox runat= "Server" cssclass= "item" id= "Txttextcount" ></asp:TextBox>
<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server" controltovalidate= "Txttextcount" validationgroup= "CreateTextbox" display= "Dynamic"
Errormessage= "Required to input content!" ></asp:RequiredFieldValidator>
<asp:regularexpressionvalidator id= "RegularExpressionValidator1" controltovalidate= "Txttextcount" validationgroup= "CreateTextbox" display= "Dynamic"
runat= "Server" errormessage= "only number is valid!" validationexpression= "^\d+$" ></asp:RegularExpressionValidator>
<asp:button runat= "Server" id= "btncreate" text= "Create TextBox List" validationgroup= "CreateTextbox"
onclick= "Btncreate_click"/>
<asp:button runat= "Server" id= "Btnok" text= "Get TextBox Content" validationgroup= "Showlistcontent"
onclick= "Btnok_click"/>
</div>
<div runat= "Server" id= "Divcontrols" class= "Item" ></div>
<div runat= "Server" id= "Divmessage" >
</div>
</div>
2. Front page code:
The following are the referenced contents:
Copy Code code as follows:
<div>
<div class= "Item" >
Please input a number:
<asp:textbox runat= "Server" cssclass= "item" id= "Txttextcount" ></asp:TextBox>
<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server" controltovalidate= "Txttextcount" validationgroup= "CreateTextbox" display= "Dynamic"
Errormessage= "Required to input content!" ></asp:RequiredFieldValidator>
<asp:regularexpressionvalidator id= "RegularExpressionValidator1" controltovalidate= "Txttextcount" validationgroup= "CreateTextbox" display= "Dynamic"
runat= "Server" errormessage= "only number is valid!" validationexpression= "^\d+$" ></asp:RegularExpressionValidator>
<asp:button runat= "Server" id= "btncreate" text= "Create TextBox List" validationgroup= "CreateTextbox"
onclick= "Btncreate_click"/>
<asp:button runat= "Server" id= "Btnok" text= "Get TextBox Content" validationgroup= "Showlistcontent"
onclick= "Btnok_click"/>
</div>
<div runat= "Server" id= "Divcontrols" class= "Item" ></div>
<div runat= "Server" id= "Divmessage" >
</div>
</div>
Description, the dynamically created textbox will be loaded into the divcontrols.
Current 1/2 page
12 Next read the full text