Learning purpose: Master the use of WEB controls (2)
First of all, I want to explain that my ten-day tutorial is just to give everyone an understanding of ASP.NET, and I have skipped a lot of things. Many people on the Internet are scolding me for writing tutorials, thinking that they can’t learn anything in ten days, and they still can’t learn anything after reading my tutorials. I think they may have overestimated my tutorials. There are many books out there, and I learned about ASP and ASP.NET by reading them. All I want to do is hope that after reading my tutorial, everyone will feel that ASP and ASP.NET are not something that cannot be learned, and then have the confidence to learn it. I think I have to rely on myself to learn. Every book out there has its own imperfections. The key is to practice and explore on your own.
First, let’s talk about the form validation controls. In the past, when we did form validation, if it was client-side JAVASCRIPT, it couldn’t be beautiful and unified, and it could also be blocked by starting the form directly in the browser; if we did server-side validation, it would I found that it is also very troublesome to have the test results reflected at the front desk. Well now, the many inspection controls provided by ASP.NET allow us to not need to consider whether it is client-side inspection or server-side inspection, so that we do not need to consider how to output the inspection results.
Check to see if the test form control is filled in:
controltovalidate is the ID of the control you want to test; by default, the error message will not be displayed, and the place will be reserved. If display="dynamic" is used, the place where the error message will not be displayed will not be empty; forecolor="#ff0000 " font-name="宋体" font-size="9pt" is to set the color, font and size of the error message font; text="Please fill in" is the error message displayed when no content is filled in; don't forget the last runat="server". Now that the verification control is placed behind the textbox, the error message is also displayed behind the textbox, or it can be placed elsewhere.
Let’s take a look at the test control that compares the form control’s data with another data:
Here is the first password box that the user needs to fill in
We often set up another password box for users to fill in again:
controltocompare="password1" is the control that needs to be compared; operator="equal" is to set the comparison operation: whether it is equal (there are also NotEqual: not equal, LessThan: less than, GreaterThan: greater than, when this comparison operation is not met error message is displayed).
I mentioned before that the BUTTON control CausesValidation=true/false is used to set whether the form submitted by the button is checked, which are the several check controls here. If CausesValidation=true, pressing the button will first check whether they have passed the check of the check control. .
Two more points:
1. Every control that can be displayed has an attribute of whether to display it, such as username.Visible=false; which hides the previous username control; and if you want to apply CSS to the control, just write: cssclass="", Instead of class="" in previous HTML.
2. All WEB controls must be included, otherwise an error will occur.
That’s the end of today. Please continue to look back. Next time we’ll start talking about ADO.NET.