To simulate a composite control with a dynamic control (i)

Source: Internet
Author: User

Dynamic control, composite control, I believe we are already very familiar with. As long as the same display and function, in what way to achieve should depend on the actual situation. What I have encountered in a project is that there are many pages already, but each page does not use the validation control to verify the validity of the input.

To achieve the same display effect:

The conventional approach is to generate RequiredFieldValidator, RangeValidator, CompareValidator, RegularExpressionValidator, and a selection of each textbox for each page. Filteredtextboxextender. But this method, need each page to add, and unified adjustment effect, the workload is too large.

Composite control: Write a composite control that adds validation controls by parameter. This also needs to be added uniformly on the page (1/3 of the effort is about the first option), and you need to change the background control type declaration (my background code is in another assembly).

Dynamic CONTROLS: Writes a control that inherits directly from the TextBox and, where appropriate, adds validation controls by parameter. This also needs to be unified in the page changes (workload and composite control method is equivalent), but the background code do not make changes.

The first two kinds, everyone is not unfamiliar, I will not long-winded. Here, just the way to use dynamic control to achieve the above function.

Let's look at how to use it:

<!--must enter-->
<facade:stringtextbox options= "required" helpmessage= "Please enter user name" Displayname= "username"
runat= "Server" id= "StringTextBox1" MaxLength = "/><br/>"
<!--must be entered, only digital-->
<facade:stringtextbox options= "required,filtered" helpmessage= "Please enter user name"
Filtertype= "Numbers" displayname= "username" runat= "server" id= "StringTextBox2" MaxLength = "/><br/>"

<!--must be entered, only numbers can be entered, the value range is 0-400-->
<facade:numbertextbox runat= "server" ID = "Tbcount" minvalue= "0" maxvalue= "qty" displayname= "Quantity"
Helpmessage= "Please enter quantity"/>
<!--must be entered, only numbers can be entered, the value range is 0-400-->
<facade:moneytextbox runat= "server" ID = "NumberTextBox1" minvalue= "0" maxvalue= "400"
Displayname= "Amount" helpmessage= "Please enter Amount"/>

<!--must enter, the string entered must start with ABC-->
<facade:regextextbox runat= "Server" options= "Required" validationexpression= "^abc.+$"
Id= "Tbregex" displayname= "regular Test" maxlength= "example=" abc123,abceee "helpmessage=" Please enter the regular test "/>
<!--must be a mobile number-->
<facade:phonetextbox runat= "Server" id= "Tbmobile" phonetypes= "mobile" displayname= "Cell phone number"
Maxlength= "example=" "13988888888" helpmessage= "Please input mobile phone number"/>
<!--must be a cell phone number, or phone-->
<facade:phonetextbox runat= "Server" id= "Tbphonemobile" phonetypes= "Phone,mobile" displayname= "mobile number"
Maxlength= "example=" "13988888888,0311-88886666" helpmessage= "Please input mobile phone number"/>

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.