1

I have this fields, with visible = "false" I can access it via the cs page in backend, but how can I acess this control with jquery? I little code might help..

<tr>
  <td class="TDCaption" style="text-align: left">
    <asp:Label ID="lblMsg" runat="server" EnableViewState="False" ForeColor="#CC0000"></asp:Label>
    <div class="DivStyleWithScroll" style="width: 100%; overflow: scroll; height: 250px;">
      <asp:GridView ID="grdReport" runat="server" AutoGenerateColumns="False"
      DataKeyNames="CustCode" ShowFooter="True" EmptyDataText="No record found"
      PageSize="50" CssClass="mGrid" onrowdatabound="grdReport_RowDataBound">
        <Columns>
          <asp:TemplateField Visible="false">
              <ItemTemplate>
                  <asp:Label ID="lblCustCodes" runat="server" Text='<%# Eval("CustCode") %>' CssClass="grdCustName"></asp:Label>
              </ItemTemplate>
          </asp:TemplateField>
          <%--other columns--%>

The jquery is

 $('#<%=btnCompare.ClientID%>').click(function () {
            if ($(':checkbox:checked').size() == 0) {
            }
            else {
                custList = $(':checkbox:checked').map(function () { return $(this).closest('tr').find('.grdCustName').text() }).get();
                alert(custList);
            }
    });
2
  • 3
    I think I'm right in thinking that .Visible = false will stop the control from being rendered in the HTML. Have you checked the HTML source sent to the browser? Commented Aug 23, 2012 at 10:23
  • 1
    @freefaller You're entirely right. Make that the answer Commented Aug 23, 2012 at 10:24

3 Answers 3

2

I believe setting .Visible = false will stop the control from being rendered into the HTML, so the jQuery will simple not be able tofind it.

Instead, for code-behind, try using...

ctrl.Style("display") = "none"

Or on the markup, try using the following attribute on the control...

style="display:none"
Sign up to request clarification or add additional context in comments.

Comments

0

If Visible is false, then the control did not go down to the client, so you cannot directly access it from javascript/jquery: it simply isn't there. you can put the control's value in some hidden field and then can access it. as they are never visible in frontend. Hiddenfields are visible only in HTML source.

Comments

0

Label.ForeColor = System.Drawing.Color.Transparent in code behind

then set the Label Visible to true

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.