Required Field Validator Example

Here i am giving sample code snipps to create required field validator

Code:

<%@ Page Title=”Home Page” Language=”C#” MasterPageFile=”~/Site.master” AutoEventWireup=”true”
CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<asp:Content ID=”HeaderContent” runat=”server” ContentPlaceHolderID=”HeadContent”>
</asp:Content>
<asp:Content ID=”BodyContent” runat=”server” ContentPlaceHolderID=”MainContent”>
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox runat=”server” ID=”txtName”></asp:TextBox>
<asp:RequiredFieldValidator ID=”RequiredFieldValidator1″ runat=”server” ControlToValidate=”txtName”
ErrorMessage=”Password is required.” ValidationGroup=”vgExample”>
<asp:Image ID=”Image1″ ImageAlign=”AbsMiddle” runat=”server” ImageUrl=”~/Images/validation.png”
AlternateText=”” Style=”cursor: pointer” ToolTip=”Password is required.” />
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Button runat=”server” ID=”btnServer” Text=”Submit” ValidationGroup=”vgExample” />
</td>
</tr>
</table>
</asp:Content>

Screenshot:

 

Image

 

 

Image