Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using
JavaScript
document.getElementById('<%=myID.ClientID%>').value; 

I am able to retrieve the values of asp:TextBox controls but Not the values of asp:Label controls. For the Label controls, I always get
HTML
Unable to get property 'value' of undefined or null reference

Any hint for this problem? Thanks.

What I have tried:

Multiple Tries on the Label controls but not successful.
Posted
Updated 4-Mar-16 4:11am
v2

1 solution

A <asp:Label> renders as either a <span> or a <label> element. Those elements don't have a value property. Instead, you would need to read the innerHTML property to get the text of the label.

However, the error message suggests that your label element doesn't exist in the document. You need to view the rendered source of your page, check the value you're passing to getElementById, and make sure there's an element with that ID in the document.
 
Share this answer
 
v2
Comments
s yu 4-Mar-16 10:47am    
Also used .innerHTML but the document.getElementById('<%=myLabelID.ClientID%>') is null (also as you pointed out). In the .aspx.cs, the myLabel.Text does have a return value. Don't know why this control is null in JS. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900