Common verification controls in Asp.net 2.0

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>
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.