The fourth day of the 10 day society asp.net

Source: Internet
Author: User
asp.net learning Purpose: Mastering the use of Web controls (II.)

First of all, I would like to explain that my 10 days tutorial is just a let people have a knowledge of asp.net, I also skipped a lot of things. There are a lot of people on the internet scold me to write tutorials, think 10 days nothing will be learned, read my tutorial or nothing, I think they may be overestimated my tutorial. There are a lot of books outside, about ASP and asp.net, I just look at the books outside to learn. All I have to do is hope that you can read my tutorial and feel that ASP and asp.net are not learning things and then have the confidence to learn it. I want to learn or rely on their own, outside each book also has its own writing of the not thoughtful place, the key also need their own practice plus exploration.

First of all, the validation controls for the form, before we do form verification, if it is the client's JavaScript, can not do aesthetic unity, but also by directly in the browser to teach form to screen; if we do server-side validation, we will find that the test results in front of the report is also very troublesome things. Okay now, ASP. NET provides a lot of test controls so that we do not need to consider whether the client or server side test, let us not consider how to output the test results.

Check to see if the form control is a completed inspection control first:
<asp:textbox id= "username" runat= "server" cssclass= "TextBox"/>
<asp:requiredfieldvalidator controltovalidate= "username" display= "dynamic" forecolor= "#ff0000" font-name= "Song Body" Font-size= "9pt" text= "please fill in" runat= "Server"/>
ControlToValidate is the ID of the control you want to verify; By default, no error message is displayed and the place is preserved, and if display= "dynamic" is used, the place where the error message is not displayed will not be vacated; forecolor= "#ff0000" Font-name= "Song Body" font-size= "9pt" is to set the error message font color, font, size, text= "Please fill in" is when the content is not filled out when the error message; Don't forget the last runat= "server". Now that the validation control is placed behind the textbox, the error message is also displayed behind the TextBox and can be placed elsewhere.

Take a look at the validation controls that compare the data of the form control with another data:
<asp:textbox id= "Password1" runat= "server" textmode= "password" cssclass= "textbox"/>
<asp:requiredfieldvalidator controltovalidate= "Password1" display= "dynamic" forecolor= "#ff0000" font-name= "Song Body" Font-size= "9pt" text= "please fill in" runat= "Server"/>
This is the first password box that needs to be filled in by the user.
We will often set up a password box to allow users to fill in again:
<asp:textbox id= "Password2" runat= "server" textmode= "password" cssclass= "textbox"/>
<asp:requiredfieldvalidator controltovalidate= "Password2" display= "dynamic" forecolor= "#ff0000" font-name= "Song Body" Font-size= "9pt" text= "please fill in" runat= "Server"/>
<asp:comparevalidator controltovalidate= "Password2" controltocompare= "Password1" "display=" dynamic "operator=" Equal "forecolor=" #ff0000 "font-name=" Arial font-size= "9pt" text= "Confirm Failed" runat= "server"/>
Controltocompare= "Password1" is the control that needs to be compared; operator= "equal" is the set comparison operation is: whether equal (and notequal: Not Equal, LessThan: Less Than, GreaterThan: greater Than , and error messages are displayed when the comparison operation is not met.

Previously, the button control Causesvalidation=true/false to set the buttons to submit the form is not inspected is also a few test controls here, if the causesvalidation= True, pressing the button will first detect whether the test has passed the validation control.

Let's say two more:
Each control that can be displayed has properties that are not displayed, such as username. Visible=false is hiding the previous username control, and that is, if you want to apply CSS to the control, write it: cssclass= "" Instead of class= "" in the previous HTML.
Second, all Web controls must be included in the <form runat= "Server" ></form>, otherwise there will be an error.

Today is the end, please continue to look back, the next start will say ado.net.


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.