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"/>