Common verification controls in Asp.net 2.0
Last Update:2018-12-07
Source: Internet
Author: User
Several common verification controls in Asp.net 2.0 are easy to use. I will post some examples below. Code
<Form ID = "form1" runat = "server">
<Div>
<Font color = "blue"> verification control requirefieldvalidator: </font>
<Br>
<Asp: Label id = "label1" text = 'My name: 'runat = server/>
<Asp: textbox id = 'tb' runat = "server" width = 100px> </ASP: textbox>
<Asp: button id = 'mybtn 'text =' validate 'runat = 'server'/>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator1"
Controltovalidate = 'tb'
Runat = "server"
Errormessage = "Enter name"
Setfocusonerror = "true">
</ASP: requiredfieldvalidator>
</Div>
<Br/>
<Div>
<Font color = "blue"> verification control comparevalidator: </font>
<Br>
Password: & nbsp; <asp: textbox id = 'psw' runat = "server" width = 100px textmode = PASSWORD> </ASP: textbox>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator2"
Controltovalidate = 'psw'
Runat = "server"
Errormessage = "enter the password"
Setfocusonerror = "true">
</ASP: requiredfieldvalidator>
<Br>
Input again: <asp: textbox id = 'psw' runat = server width = 100px textmode = PASSWORD> </ASP: textbox>
<Asp: comparevalidator runat = Server
Id = 'comparevalidator1'
Controltovalidate = 'psw'
Controltocompare = 'repsw'
Errormessage = 'inconsistent inputs'
Setfocusonerror = "true">
</ASP: comparevalidator>
<Br/>
<Asp: button runat = server text = 'Submit' id = 'btn '/>
</Div>
<Br/>
<Div>
<Font color = "blue"> verification control rangevalidator: </font>
<Br/>
Value: <asp: textbox id = 'tb1 'runat = Server> </ASP: textbox>
<Asp: rangevalidator id = 'rangevalidator1'
Runat = Server
Controltovalidate = 'tb1'
Type = integer
Minimumvalue = 0
Maximumvalue = 255
Setfocusonerror = true
Errormessage = 'enter a value of 0-255 '>
</ASP: rangevalidator>
<Br/>
<Asp: button id = "button1" runat = server text = 'Submit'/>
</Div>
<Br/>
<Div>
<Font color = "blue"> verify the control regularexpressionvalidator: </font>
<Br/>
Value: <asp: textbox id = 'tb2' runat = Server> </ASP: textbox>
<Asp: regularexpressionvalidator id = "regularexpressionvalidator1" runat = Server
Controltovalidate = 'tb2'
Validationexpression = '[A-Za-Z]'
Setfocusonerror = true
Errormessage = 'enter English '>
</ASP: regularexpressionvalidator>
<Br/>
<Asp: button id = "button2" runat = server text = 'Submit'/>
</Div>
<Br/>
<Div>
<Font color = "blue"> verification control validationsummary: </font>
<Br/>
Your ID: <asp: textbox id = 'b2' runat = Server> </ASP: textbox>
<Asp: requiredfieldvalidator id = "regularexpressionvalidator2" runat = Server
Controltovalidate = '83'
Setfocusonerror = true
Errormessage = 'enter your id'>
</ASP: requiredfieldvalidator>
<Br/>
<Asp: button id = "button4" runat = server text = 'Submit'/>
<Br>
<Div>
<Asp: validationsummary id = "regvalidationsummary" runat = "server"
Headertext = "input error" displaymode = "bulletlist"/>
</Div>
</Div>
<Br/>
<Div>
<Font color = "blue"> customvalidator: </font>
<Br/>
<Asp: dropdownlist id = "list" runat = "server">
<Asp: listitem text = "select" value = "0"> </ASP: listitem>
<Asp: listitem text = "Item1" value = "A"> </ASP: listitem>
<Asp: listitem text = "item2" value = "B"> </ASP: listitem>
</ASP: dropdownlist>
<Asp: customvalidator id = "customvalidator1" runat = Server
Controltovalidate = 'LIST'
Errormessage = 'select A list'
Setfocusonerror = true
Display = "dynamic"
Onservervalidate = "customvalidator1_servervalidate">
</ASP: customvalidator>
<Br/>
<Asp: button id = "button3" runat = server text = 'Submit'/>
<Br/>
</Div>
</Form>