Using a JavaScript class in ASP and passing "object.ClientId"

I have a JavaScript class called ControlValidation.js.  

On my ASP page I have a reference to that class using:
<script type="text/javascript" language="javascript" src="<%= Request.ApplicationPath %>/JS/ControlValidation.js"></script>

In my code behind I call the isValidPhoneNumber function using:
btnSave.Attributes.Add("OnClick", "return isValidPhoneNumber(" & tbPhoneNum.Text & ")")

JavaScript code looks like:
function isValidPhoneNumber(validationText)
    rePhoneNumber = new RegExp(/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/);
    if (!rePhoneNumber.test(validationText))
        return false;

    return true;

While this works fine, I want to pass in the ClientId of an ASP label so I can set the text when the validation fails.  I tried btnSave.Attributes.Add("OnClick", "return isValidPhoneNumber(" & tbPhoneNum.Text & "," & lblErrorMessage.ClientId & ")") and in the JS function I added myMsg.value = "Invalid Phone Number" but this doesn't seem to work.

How can I pass the label to my JS function so I can assign text to it?
Who is Participating?
burakiewiczConnect With a Mentor Commented:
try this as the onclick. in csharp it ClientID, not sure if it is different in vb
("OnClick", "return isValidPhoneNumber('" & tbPhoneNum.Text & "','" & lblErrorMessage.ClientId & "')")

then just get the element by the clientID
function isValidPhoneNumber(validationText,labelid)
var label=document.getElementById(labelid);
nightshadzAuthor Commented:
Awesome thanks!

I also needed to add label.innerHTML = "my text"; to assign text to the label.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.