In this article i explain you how to use validation summary control in registration form
Properties of validation summary control:
HeaderText - The header text for the validation summary control
ShowSummary - Whether to display the summary text of all the validation errors
ShowMessageBox - Whether to display a message box with all the validation errors
DisplayMode - Display format for the summary.
DisplayMode can be List, BulletList, SingleParagraph
design:-
<div style="margin-top:50px;border:1px solid black;width:420px;padding:10px;margin-left:50px;">
<table>
<tr>
<td colspan="2">
<h2>Registration Form</h2>
</td>
</tr>
<tr>
<td>First Name</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvFirstName" runat="server" Text="*" ControlToValidate="txtFirstName" ForeColor="Red" ErrorMessage="Enter FirstName" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Last Name</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvLastName" runat="server" Text="*" ControlToValidate="txtLastName" ForeColor="Red" ErrorMessage="Enter LastName" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Gender</td>
<td>
<asp:DropDownList ID="ddlGender" runat="server" Height="25px" Width="170px">
<asp:ListItem Text="Select Gender" Value="-1"></asp:ListItem>
<asp:ListItem Text="Male" Value="1"></asp:ListItem>
<asp:ListItem Text="Female" Value="2"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RfvGender" runat="server" Text="*" ControlToValidate="ddlGender" ForeColor="Red" InitialValue="-1" ErrorMessage="Select Gender" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Email</td>
<td>
<asp:TextBox ID="txtEmail" runat="server" TextMode="Email"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvEmail" runat="server" Text="*" ControlToValidate="txtEmail" ForeColor="Red" ErrorMessage="Enter Email" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Password</td>
<td>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvPassword" runat="server" Text="*" ControlToValidate="txtPassword" ForeColor="Red" ErrorMessage="Enter Password" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Confirm Password</td>
<td>
<asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvConfirmPassword" runat="server" Text="*" ControlToValidate="txtConfirmPassword" ForeColor="Red" ErrorMessage="Enter Confirm Password" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="Cmp1" runat="server" ControlToValidate="txtConfirmPassword" Text="*" Operator="Equal" ControlToCompare="txtPassword" ForeColor="Red" Display="Dynamic" SetFocusOnError="true" ErrorMessage="Password and confirm password must match"></asp:CompareValidator>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary ID="ValidationSummary1" DisplayMode="List" ForeColor="Red" ShowMessageBox="true" ShowSummary="true" runat="server" />
</td>
</tr>
</table>
</div>
Output:-
Properties of validation summary control:
HeaderText - The header text for the validation summary control
ShowSummary - Whether to display the summary text of all the validation errors
ShowMessageBox - Whether to display a message box with all the validation errors
DisplayMode - Display format for the summary.
DisplayMode can be List, BulletList, SingleParagraph
design:-
<div style="margin-top:50px;border:1px solid black;width:420px;padding:10px;margin-left:50px;">
<table>
<tr>
<td colspan="2">
<h2>Registration Form</h2>
</td>
</tr>
<tr>
<td>First Name</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvFirstName" runat="server" Text="*" ControlToValidate="txtFirstName" ForeColor="Red" ErrorMessage="Enter FirstName" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Last Name</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvLastName" runat="server" Text="*" ControlToValidate="txtLastName" ForeColor="Red" ErrorMessage="Enter LastName" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Gender</td>
<td>
<asp:DropDownList ID="ddlGender" runat="server" Height="25px" Width="170px">
<asp:ListItem Text="Select Gender" Value="-1"></asp:ListItem>
<asp:ListItem Text="Male" Value="1"></asp:ListItem>
<asp:ListItem Text="Female" Value="2"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RfvGender" runat="server" Text="*" ControlToValidate="ddlGender" ForeColor="Red" InitialValue="-1" ErrorMessage="Select Gender" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Email</td>
<td>
<asp:TextBox ID="txtEmail" runat="server" TextMode="Email"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvEmail" runat="server" Text="*" ControlToValidate="txtEmail" ForeColor="Red" ErrorMessage="Enter Email" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Password</td>
<td>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvPassword" runat="server" Text="*" ControlToValidate="txtPassword" ForeColor="Red" ErrorMessage="Enter Password" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Confirm Password</td>
<td>
<asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvConfirmPassword" runat="server" Text="*" ControlToValidate="txtConfirmPassword" ForeColor="Red" ErrorMessage="Enter Confirm Password" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="Cmp1" runat="server" ControlToValidate="txtConfirmPassword" Text="*" Operator="Equal" ControlToCompare="txtPassword" ForeColor="Red" Display="Dynamic" SetFocusOnError="true" ErrorMessage="Password and confirm password must match"></asp:CompareValidator>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary ID="ValidationSummary1" DisplayMode="List" ForeColor="Red" ShowMessageBox="true" ShowSummary="true" runat="server" />
</td>
</tr>
</table>
</div>
Output:-
No comments:
Post a Comment