How check text value of ASP.NET label using Javascript

  • Thread starter Thread starter Cirene
  • Start date Start date
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!
 
This seems to work...

if
(document.getElementById("ctl00_ContentPlaceHolder1_lblUserRole").innerText
== "999")
 
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
 
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
 
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
 
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
 
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
 
Back
Top