Give a sample code snippet for ASP.NET RequiredFieldValidator server control?

Posted by Tripati_tutu under HTML 5 category on | Points: 40 | Views : 4220
You have declared a textbox on the page. So the use of RequiredFieldValidator is, you must have to pass some value in the textbox. You can validate this with the help of a property called "ControlToValidate".

Sample Code:
<form id="Form1" runat ="server" action ="" >
Enter Your name in the textbox:
<asp:TextBox ID ="txtName" runat ="server" />
<br /><br />
<asp:Button ID="Button1" Text ="submit" runat ="server" />
<br />
<asp:RequiredFieldValidator ID ="rfvName" runat ="server" ControlToValidate ="txtName" CssClass ="AlertText" Display ="Dynamic" EnableClientScript ="true" >
<img src ="image1.JPG" alt ="" />
Name is required !

Comments or Responses

Login to post response