ASP. NET dynamically writes controls to Server Page 1/2

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.