Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Write a program to associate labels with asp controls so

that when ever label is clicked it takes cursor to the


associated label. Final output should be like this:










<script language="javascript" type="text/javascript">
function JSValidate(source, args) {
var element = document.getElementById('<%=usernameTextBox.ClientID %>');
if (element.value.length >= 6 && element.value.length <=15)
{
args.IsValid = true;
}
else {
args.IsValid = false;
}
}
</script>
<style type="text/css">
.style2
{
font-size: small;
font-family: Verdana;
}
</style>
<h2 style="color: Green">
CustomValidator in ASP.NET 4 , C#</h2>
<br />
<strong><span class="style2">User Name:</span>
</strong>
<br />
<asp:TextBox ID="usernameTextBox" runat="server" Font-Names="Verdana" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="submitButton" runat="server" Text="Submit" Width="85px" />
<br />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="The length between 6 to 15 character."
ControlToValidate="usernameTextBox" ForeColor="Red"
ClientValidationFunction="JSValidate">
</asp:CustomValidator>


<table>
<tbody><tr>
<td>
<asp:label text="Name" id="lblName"
associatedcontrolid="txtName" runat="server">
</asp:label></td>
<td>
<asp:textbox runat="server" id="txtName">
</asp:textbox></td>
</tr>
<tr>
<td>
<asp:label text="Age" id="lblAge" associatedcontrolid="txtAge"
runat="server">
</asp:label></td>
<td>
<asp:textbox runat="server" id="txtAge">
</asp:textbox></td>
</tr>
<tr>
<td>
<asp:label text="Email" id="lblEmail"
associatedcontrolid="txtEmail" runat="server">
</asp:label></td>
<td>
<asp:textbox runat="server" id="txtEmail">
</asp:textbox></td>
</tr>
</tbody></table>

You might also like