In web development, many input items on the Web page must be verified before being submitted to the server. ASP. NET provides a series of verification controls, allowing you to easily verify the content of the text box (more in-depth verification can be achieved through regular expressions, and will be introduced later ).
Requiredfieldvalidator Control
This control is used to change an input item to a required field, meaning that the input item cannot be blank. It has an attribute used to bind the verified control: controltovalidate, for example, <asp: requriedfieldvalidator id = "rfvname" runat = "server" Controltovalidate = "txtname" Errormessage = "Enter name" text = "*"> <asp: requriedfieldvalidator/> Code Use the requriedfieldvalidator control to verify whether the txtname of the text box is empty.
Rangevalidator Control This control is used to verify whether the data of the input item is within the specified range. It is invalid to check the data of this range. It is also bound to the verified control through the controltovalidate attribute, the minimumvalue and maxmumvalue attributes are used to determine the minimum and maximum values of a specified range. For example, <asp: rangevalidator id = "rvmonth" Controltovalidate = "txtmonth" Minimumvalue = "1" Maxmumvalue = "12" Errormessage = "the month must be between 1 and 12" type = integer
Runat = "server"/> This code is used to verify whether the input accepted by the txtmonth control is between 1 and 12
Validationsummery Control
This control is used for verification on the summary page. Program The error message is displayed on the webpage or in a prompt box. For example, add the following code below the above Code about rangevalidator: <asp: validationsummery id = "vsmonth" runat = "server"
Showmessagebox = "true" Showsummery = "false" /> If you enter "13" in the txtmonth text box, a prompt box is displayed, showing "the month must be between 1 and 12 ". Properties Showmessagebox andShowsummery is used to determine whether the error summary is displayed in the prompt box or on the webpage. I am a beginner in B/S development. I hope this article Article It can be helpful for beginners to verify controls