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













Steps of execution













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


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, February 21, 2013

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250