如何通过JavaScript查找控件并获取ClientID

问题描述 投票:0回答:1

我有以下aspx代码:

<div id="IsAccountingOk" class="modalDialog">
    <div>
        <a href="#close" title="Luk" class="close">X</a><br />
        <asp:Label ID="lblIsAccountingOkHeader" runat="server" Text="Kassekladde:" Font-Size="Large"></asp:Label><br /><br />
        <asp:Label ID="lblMessage" runat="server" Text="Der skal først vælges regnskabsår!"></asp:Label><br />
        <br />
        <asp:Button ID="btnIsAccountingOK" runat="server" Text="Ok" OnClick="btnIsAccountingOK_Click"/>
    </div>
</div>

但是我如何访问'IsAccountingOk'并通过document.getElementByID获取它?我也尝试了以下失败的方法:-(

$(document).ready(function () {
    var session = '<%=Session["AccountYearID"] == null%>';
    if (session.toLowerCase() == 'true') {
        document.getElementById('<%= this.FindControl("IsAccountingOk").ClientID %>').style.display = 'block';
    }
});

发生以下错误:

System.NullReferenceException:'对象引用对象直到可以接受为止。” (错误消息是丹麦语-但是我从FindControl得到一个空值)

有什么想法吗?

提前感谢。

问候迈克尔

javascript c# html asp.net
1个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.