How check text value of ASP.NET label using Javascript

C

Cirene

I have an asp.net label on my webform. (The webform is based on a master
page.)

Using javascript how do I check the text value of the ASP.NET label? The
label is called lblCar.

Thanks!
 
C

Cirene

This seems to work...

if
(document.getElementById("ctl00_ContentPlaceHolder1_lblUserRole").innerText
== "999")
 
C

Cirene

Wow! Thanks!

Mark Rae said:
[top-posting corrected]
This seems to work...

if
(document.getElementById("ctl00_ContentPlaceHolder1_lblUserRole").innerText
== "999")

Avoid hard-coding client-side element names, as they are not set in
stone...

Use this instead:
document.getElementById('<%=lblCar.ClientID%>').innerText
 
C

Cirene

In this case what is "ClientID" used for? Thanks...

Mark Rae said:
[top-posting corrected]
This seems to work...

if
(document.getElementById("ctl00_ContentPlaceHolder1_lblUserRole").innerText
== "999")

Avoid hard-coding client-side element names, as they are not set in
stone...

Use this instead:
document.getElementById('<%=lblCar.ClientID%>').innerText
 
C

Cirene

oh i guess that corresponds to the ID of the label - sorry for such a stupid
question :) hehe

Cirene said:
In this case what is "ClientID" used for? Thanks...

Mark Rae said:
[top-posting corrected]
I have an asp.net label on my webform. (The webform is based on a
master page.)

Using javascript how do I check the text value of the ASP.NET label?
The label is called lblCar.

This seems to work...

if
(document.getElementById("ctl00_ContentPlaceHolder1_lblUserRole").innerText
== "999")

Avoid hard-coding client-side element names, as they are not set in
stone...

Use this instead:
document.getElementById('<%=lblCar.ClientID%>').innerText
 
J

Jonathan Wood

Right, it's the ID that is put in the generated HTML code.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Cirene said:
oh i guess that corresponds to the ID of the label - sorry for such a
stupid question :) hehe

Cirene said:
In this case what is "ClientID" used for? Thanks...

Mark Rae said:
[top-posting corrected]

I have an asp.net label on my webform. (The webform is based on a
master page.)

Using javascript how do I check the text value of the ASP.NET label?
The label is called lblCar.

This seems to work...

if
(document.getElementById("ctl00_ContentPlaceHolder1_lblUserRole").innerText
== "999")

Avoid hard-coding client-side element names, as they are not set in
stone...

Use this instead:
document.getElementById('<%=lblCar.ClientID%>').innerText
 
C

Cirene

Danke Schon!

Peter Bucher said:
Hi Cirene

I have written a german article about identification of ASP.NET Controls.
Maybe you`r be able to understand the Google Translated Page:
-
http://translate.google.com/transla...&hl=de&ie=UTF-8&oe=UTF-8&prev=/language_tools

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top