ASP.NET label Control and Javascript


I have User ID and  Password Text boxex.
 and I need to check if password contains user id(i.e password and user id should not be the same) and display errormessage using a ASP.NET label control

I'm doing this validation

function CheckPassword()
                  lblErrorMessage.Text=">>> Your password should not contain your UserID. Please enter a new password."
                  return false;
            return true;


I'm calling this function in form onsubmit event.
I'm getting the following message( lblErrorMessage is null or not defined').
lblErrorMessage is a label control with stylesheet class attached to it for color

What is wrong with this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I don't think you can refer to your ASP.NET label control using Javascript. You will need to use VBScript or something along those lines.
ASP .Net Labels get rendered as <Span> . So after the page is generated check what gets generated. For Span you can try giving

document.all.lblErrorMessage.innerHTML = "The username and passwords are same"

Well there may be other possibilities too. Please let me know if the above solution works

You have to mention the document.forms(0).lblErrorMessage.value instead of

note I had changed the text as value and document.forms(0) added in front

try and give ur comments
Hi Arun,

Since the Label gets rendered as a span and span does not usually have a value attribute. So it is something like this

<span>TEXT HERE</span>

so "TEXT HERE" is the innerHTML part of it. So it has to be

document.forms(0).lblErrorMessage.innerHTML = "Changed Text"


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.