Articles → .NET → Displaying Validation Error Message In Login Control In Asp.Net
Displaying Validation Error Message In Login Control In Asp.Net
Software Requirement
Prerequisite Knowledge
- Basics about .net programming
- How to create website using visual studio?
- Basics about validation controls in .net
- Basics about controls like login control, change password control etc.
Steps Of Execution
- Create a new project
- Add login control to the page
- Add validation Summary to the page
- Add code to bind validation group
Create A New Project
Click to Enlarge
Add Login Control To The Page
<asp:Login ID="Login1" runat="server">
</asp:Login>
Add Validation Summary To The Page
<asp:Login ID="Login1" runat="server"></asp:Login>
<asp:ValidationSummary ID="summary" runat="server"/>
Add Code To Bind Validation Group
protected void Page_Load(object sender, EventArgs e) {
summary.ValidationGroup = ((BaseValidator) Login1.FindControl("UserNameRequired")).ValidationGroup;
}
Code Explanation
<table cellspacing="0" cellpadding="1" id="MainContent_Login1" style="border-collapse:collapse;">
<tr>
<td>
<table cellpadding="0">
<tr>
<td align="center" colspan="2">Log In</td>
</tr>
<tr>
<td align="right">
<label for="MainContent_Login1_UserName">User Name:</label>
</td>
<td>
<input name="ctl00$MainContent$Login1$UserName" type="text" id="MainContent_Login1_UserName" />
<span id="MainContent_Login1_UserNameRequired" title="User Name is required." style="visibility:hidden;">*</span>
</td>
</tr>
<tr>
<td align="right">
<label for="MainContent_Login1_Password">Password:</label>
</td>
<td>
<input name="ctl00$MainContent$Login1$Password" type="password" id="MainContent_Login1_Password" />
<span id="MainContent_Login1_PasswordRequired" title="Password is required." style="visibility:hidden;">*</span>
</td>
</tr>
<tr>
<td colspan="2">
<input id="MainContent_Login1_RememberMe" type="checkbox" name="ctl00$MainContent$Login1$RememberMe" />
<label for="MainContent_Login1_RememberMe">Remember me next time.</label>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<input type="submit" name="ctl00$MainContent$Login1$LoginButton" value="Log In" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$Login1$LoginButton", "", true, "ctl00$MainContent$Login1", "", false, false))" id="MainContent_Login1_LoginButton" />
</td>
</tr>
</table>
</td>
</tr>
</table>
Output
Click to Enlarge