KentZhou
KentZhou

Reputation: 25553

how to get value in javascript for asp Label control?

Suppose I have asp Lable set in markup like:

<asp:Label ID="myID" runat="server"></asp:Label>

then set value for this Label in code behind like:

myID.Text =100

then I want get the value 100 in javascript. I tried:

document.getElementById('<%=myID.ClientID%>').value; 

but is not working. How to resolve this issue?

Upvotes: 4

Views: 45583

Answers (3)

Mohsin Afzal
Mohsin Afzal

Reputation: 31

var label=$("#<%myID.ClientID%>").html();

Upvotes: -2

Enkode
Enkode

Reputation: 4783

With jquery you need to use the html property.

var g = $('#<%=myID.ClientID%>').html();

These will NOT work with jquery

  • $('#<%=myID.ClientID%>').innerText
  • $('#<%=myID.ClientID%>').innerHTML
  • $('#<%=myID.ClientID%>').val()

Upvotes: 0

Smeegs
Smeegs

Reputation: 9224

I believe that labels render as spans. Try getting the inner text.

document.getElementById('<%=myID.ClientID%>').innerText;

Upvotes: 10

Related Questions