Skip to content Skip to sidebar Skip to footer

How To Use Javascript To Get Asp.net Web Forms Label's Value?

I have the following label control: Its value is filled in the Page_Load event. I attached

Solution 1:

labels don't have a value. They have innerHTML and innerText.

Solution 2:

Use JQuery and it will run in all browsers and platforms, something like:

$('#<%= lblStatus.ClientID %>').next().text();

source: JQuery: getting the value/text/innerHtml of a checkbox in an ASP.NET CheckBoxList control

Solution 3:

Label server control renders as span. So you should get it's content by innerText. try this :

alert(lblObj.innerText);

Solution 4:

ASP.NET label server control will be rendered in complex HTML output. Like:

<spanid="ctl00_ctl00_ContentPlaceHolder1_BodyPlaceHolder_lblLanguage0"><labelclass="inputText">English</label></span>

When you use getElementById you will get span. But to set value via javascript you have to access inner label object

Solution 5:

try this

<scriptlanguage="javascript"type="text/javascript">functiongetlabelvalue()
{
   var value1 = document.getElementById('<%=labelID.ClientID%>').value;
            if (value1.length < 1)
                value1 = 0;
}    
 </script>

Post a Comment for "How To Use Javascript To Get Asp.net Web Forms Label's Value?"