asp.net dynamic Write server-side controls 1th/2 page _ Practical Tips

Source: Internet
Author: User
Tags numeric value
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
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.