Everyone is familiar with dynamically writing HTML Tag controls. This article focuses on how to dynamically write controls to the server and obtain the attributes of the server-side controls that are dynamically written when the page is PostBack to the server.
Here, I will use a demo to describe this application.
Requirements:
1. the user enters a value (for example, 5) on the UI, and the system dynamically loads the URL address field of this value for the user;
2. the URL address entered by the user must be verified in URL format;
3. After the user submits the input content, the system returns the submitted results.
The design is as follows:
1. CSS style settings:
Reference content is as follows:
CopyCode The Code is as follows: <style type = "text/CSS">
. Item
{
Margin: 10px;
Border-bottom: solid 1px # CCC;
}
. Item2
{
Margin: 5px;
}
. Input
{
Width: 200px;
}
</Style>
2. Front-end Page code:
Copy code The Code is 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-end Page code:
Reference content is as follows: Copy code The Code is 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>
The dynamically created textbox is loaded into divcontrols.