0

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();
        alert(index);
    }

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

0

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

0

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:

    $('[id$="lbMessageIndex"]').html();
              OR
    $('[id*="lbMessageIndex"]').html();

To get the label value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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