Selective Validation (ASP.NET PROGRAM)

This enhancement allows specifying selective partial validation in a web form using validation controls. Each validation group is evaluated separately from other validation groups in the web form. You can specify Validation Groups by setting the Validation Group Property of Validation Controls to a value. All the Validation Controls with the same value set for the Validation Group property are included in the same Validation Group.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<center><H3> Validation Groups Sample</H3>
<div style="width:60%;border-bottom:blue thin solid;border-top:blue thin solid;border-left:blue thin solid;border-right:blue thin solid">
&nbsp;<br />
<center>
<table border="0">
<tr>
<td style="width: 100px; height: 23px">
User ID</td>
<td style="width: 215px; height: 23px">
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtLogin"
ErrorMessage="User ID is required" ValidationGroup="VGrpAuthenticate">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 100px; height: 23px">
Password</td>
<td style="width: 215px; height: 23px">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPassword"
ErrorMessage="Password cannot be blank" ValidationGroup="VGrpAuthenticate">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 100px; height: 21px">
NickName</td>
<td style="width: 215px; height: 21px">
<asp:TextBox ID="txtNickName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 

ControlToValidate="txtNickName"
ErrorMessage="NickName is required" ValidationGroup="VGrpAnon">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="height: 21px" colspan="2">
<br />
<asp:Button ID="btnLoginAuth" runat="server" Text="Login" ValidationGroup="VGrpAuthenticate" />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
<asp:LinkButton ID="LinkButton1" runat="server" ValidationGroup="VGrpAnon">Login as Guest</asp:LinkButton><br />
</td>
</tr>
</table>
</center>
</div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" ValidationGroup="VGrpAuthenticate" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" ValidationGroup="VGrpAnon" />
</center>
</form>
</body>
</html>

OUTPUT
 
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *