Click here to Skip to main content
14,876,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I Am Trying To Implement JavaScript Validation Inside a UserControl & calling That UserControl In An Another .aspx page

What I have tried:

function ValidateCustomerName() {<br />
    debugger;<br />
    var AptName = document.forms["form1"]["count_txtAptName"];<br />
   // var AptName = document.forms["form1"]["txtAptName"];<br />
    var lblAptName = document.getElementById('<%=WebForm1.FindControl("Label1").ClientID %>')//document.getElementById('<%=Label1.ClientID%>');//document.getElementById("count_Label1");//<br />
    if (AptName.value.length == 0) {<br />
        AptName.focus();<br />
        lblAptName.innerHTML = "Please fill Applicant Name2";<br />
        return false;<br />
    }<br />
    else if (!AptName.value.match(/^[A-Za-z ]+$/)) {<br />
        AptName.focus();<br />
        lblAptName.innerHTML = "Applicant Name contain only alphabet2";<br />
        return false;<br />
    }<br />
    else {<br />
        lblAptName.innerHTML = "";<br />
    }<br />
}<br />
Updated 15-Sep-16 0:10am
F-ES Sitecore 15-Sep-16 4:55am
What happens when you step through the code? What lines aren't working the way you'd expect?

1 solution

do not refer html elements like :


instead use :

var txt = document.getElementById("<%= txtAptName.ClientID %>").value;

hope this helps!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900