1

我有这个字段,可见=“false”我可以通过后端的cs页面访问它,但是如何使用jquery访问这个控件?我的小代码可能会有所帮助..

<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--%>

jQuery是

 $('#<%=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);
            }
    });
4

3 回答 3

2

我相信设置.Visible = false会阻止控件被呈现到 HTML 中,因此 jQuery 将无法找到它。

相反,对于代码隐藏,请尝试使用...

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

或者在标记上,尝试在控件上使用以下属性...

style="display:none"
于 2012-08-23T10:26:30.617 回答
0

如果 Visible 为 false,则控件不会传递到客户端,因此您不能直接从 javascript/jquery 访问它:它根本不存在。您可以将控件的值放入其中hidden field,然后可以访问它。因为它们在前端永远不可见。Hiddenfields仅在HTML源中可见。

于 2012-08-23T10:27:42.307 回答
0

Label.ForeColor = System.Drawing.Color.Transparent在后面的代码中

然后将标签设置Visibletrue

于 2015-06-05T11:15:32.600 回答