I have created a SharePoint 2010 visual web part. In the page load event of the user control, i am setting the value of an asp.net label.

<asp:Label ID ="lbMessageIndex" runat="server" Visible="false"></asp:Label>

protected void Page_Load(object sender, EventArgs e)
           lbMessageIndex.Text = "0";                

I also have a anchor tag with a click event getLabelValues() . In this method, when access the label value using jQuery, empty string value is returned.

function getLabelValues() {
        var index = $('#<%=lbMessageIndex.ClientID%>').text();

Note - .html() and .val() returns undefined.

2 Answers 2


The issue was with the visibility. Control was not rendered when visibility was set to false. The fix is hide it using css. display:none


This is because of the Label property Visibility="false". Instead use it as:

<asp:Label ID ="lbMessageIndex" runat="server" style="display:none;"></asp:Label>

then you can use:


To get the label value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.