Ten days to learn ASP.net (4)

Source: Internet
Author: User

Day 4

Objective: To learn how to use WEB controls (2)

First of all, I want to explain that my ten-day tutorials only let everyone know about ASP. NET, And I skipped a lot of things. Many people scold me for writing tutorials on the Internet. I think I can't learn anything for ten days. I still can't read my tutorials. I think they may have overestimated my tutorials. There are a lot of books outside. For ASP and ASP. NET, I learned to read books outside. All I have to do is hope that you can read my tutorials and think ASP and ASP. NET are not what you can't learn and then have the confidence to learn about it. I want to learn by myself. Every book on the outside also has its own inconsiderate content. The key is to practice and explore it.

First, let's take a look at the form verification control. In the past, we used form verification. If it was JAVASCRIPT on the client side, it could not be beautiful and uniform, but it could also be blocked directly by using a browser to teach the form; if we perform server-side verification, we will find it very troublesome to reflect the inspection results on the front-end. Now, there are a lot of validation controls provided by ASP. NET, so we don't need to consider whether it is a client or a server, so we don't need to consider how to output the validation results.

Check whether the form control is filled with the check control first:
<Asp: textbox id = "username" runat = "server" cssclass = "textbox"/>
<Asp: requiredfieldvalidator controltovalidate = "username" display = "dynamic" forecolor = "# ff0000" font-name = "" font-size = "9pt" text = "enter" runat =" server "/>
Controltovalidate is the ID of the control you want to check. By default, no error message is displayed and the location is retained, if display = "dynamic" is used, no error messages are displayed; forecolor = "# ff0000" font-name = "" font-size = "9pt" indicates the font color, font, and size of the error message; text = "Please fill in" is the error message displayed when no content is filled; Do not forget the last runat = "server ". Now this check control is placed behind the textbox, so the error message is also displayed behind the textbox, you can also put it elsewhere.

Let's take a look at the data of the Form Control and the validation control of another data:
<Asp: textbox id = "password1" runat = "server" textmode = "password" cssclass = "textbox"/>
<Asp: requiredfieldvalidator controltovalidate = "password1" display = "dynamic" forecolor = "# ff0000" font-name = "" font-size = "9pt" text = "enter" runat =" server "/>
Here is the first Password box to be entered by the user
We often set up another password box for 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 = "" font-size = "9pt" text = "enter" runat =" server "/>
<Asp: comparevalidator controltovalidate = "password2" controltocompare = "password1" display = "dynamic" operator = "equal" forecolor = "# ff0000" font-name = "" font-size = "9pt "text =" Confirm failed "runat =" server "/>
Controltocompare = "password1" is the control to be compared; operator = "equal" is to set whether the comparison operation is equal (and NotEqual: not equal, LessThan: less than, GreaterThan: greater, when this comparison operation is not met, an error message is displayed ).

Previously, we talked about the BUTTON control CausesValidation = true/false to set whether the form submitted by the BUTTON is verified, that is, the Inspection controls here, if CausesValidation = true, pressing the button will first check whether all of them have passed the inspection control.

Let's talk about two more points:
1. Each control that can be displayed has a display attribute, such as username. visible = false; that is, the preceding username control is hidden; that is, if you want to apply CSS to the control, write: cssclass = "" instead of class = "" in the previous HTML "".
2. All WEB controls must be included in <form runat = "server"> </form>. Otherwise, an error occurs.

This is the end of today. Please continue to look at it later. We will talk about ADO. NET next time.


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.