|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Saturday, March 25, 2006The RequiredFieldValidator Control(Chapter3)In the following example, the user is expected to enter two values. If he or she skips any one of the values and clicks the Submit button, the system will report the error. Please notice that we do not require any extra code for performing this validation.When the Submit button is clicked, the form will be sent to the server, and the server will do the automatic validation.The run-time view of this application is shown in Figure 3.50
Figure 3.50 Using the RequiredFieldValidator Control Figure 3.51 Validator1.aspx <!—- Chapter3\Validator1.aspx —> <!— Required Field Validator —> <html><head</head> <title>Example on Required Field validator</title><body> <form runat="server"><br> Enter Your Name: <asp:TextBox id="txtName" rows="1 " width="50" runat="server"/> <asp:RequiredFieldValidator id="validTxtName" runat="server" controlToValidate="txtName" errorMessage="Name must be entered" display="static"> </asp:RequiredFieldValidator></br> Hours worked? <asp:TextBox id="txtH" width ="30" runat="server" /> <asp:RequiredFieldValidator id="validTxtH" runat="server" controlToValidate="txtH" errorMessage="Hours must be entered" display="static"> </asp:RequiredFieldValidator></br> <asp:Button id="btnSubmit" runat="server" text="Submit" /> </form></body></html> |
0 Comments:
Post a Comment
<< Home