ASP.NET label Control and Javascript

Posted on 2004-11-03
Medium Priority
Last Modified: 2006-11-17

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?
Question by:AnithaB
  • 2

Expert Comment

ID: 12487588

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.
LVL 21

Expert Comment

ID: 12489582
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


Expert Comment

ID: 12491241
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
LVL 21

Accepted Solution

surajguptha earned 2000 total points
ID: 12491327
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"


Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question