How to use validation summary

Ranjeet_8
Posted by Ranjeet_8 under ASP.NET category on | Points: 40 | Views : 2440
ASPX page design :

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Testing Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtName" runat="server" MaxLength="80" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="txtName"
runat="server" ErrorMessage="Enter your first name" Display="None"
SetFocusOnError="true"
ValidationGroup="a1"> </asp:RequiredFieldValidator><br />

<asp:TextBox ID="txtLname" runat="server" MaxLength="100" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
ControlToValidate="txtLname"
runat="server" ErrorMessage="Enter your last name" Display="None"
SetFocusOnError="true"
ValidationGroup="a1"> </asp:RequiredFieldValidator>

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true"
ShowSummary="false" ValidationGroup="a1"/><br />

<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="a1"
onclick="Button1_Click1"/>

</form>
</body>
</html>

C# Code:
    
protected void Button1_Click1(object sender, EventArgs e)
{
if (Page.IsValid)
{
// Your Work here
}
}

Comments or Responses

Login to post response