无法获取未定义或空引用的属性“单击” [英] Unable to get property 'click' of undefined or null reference

查看:449
本文介绍了无法获取未定义或空引用的属性“单击”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用上一个问题中的答案,ModalPopupExtender:弹出窗口关闭文本框文件的TextChanged方法后,我能够让弹出窗口按照预期的方式工作,作为一个独立的表单,包括添加第三个按钮到模态弹出窗口:

< asp:按钮ID =btnResetrunat =serverText =StandardOnClick =btnReset_Click/> 



但是当我添加相关代码现有网站时,我收到以下错误:



错误:无法获取属性点击未定义或空引用。



该网站使用母版页,模态弹出式面板位于两个面板中,所有面板都被包围选项卡面板上的更新面板。什么会阻止执行新按钮的onclick代码?还有另一种执行代码的方法吗?



我只有弹出窗口的Ok和Cancel按钮的javascript(没有用于重置):

< script 类型 = text / javascript >
函数onOk(){
document.getElementById('btnOk')。click();
}

函数onCancel(){
document.getElementById('btnCancelRates')。click();

}
< / script >

如何调用新按钮的onclick代码?

解决方案

找到解决方案。我删除了OnCancel的JS。从ModalPopupExtendedupdates中删除了CancelControlID和OnCancelScroipt,并使用OnClick事件进行重置和取消按钮。 Ok按钮使用JS,



 <   asp:Panel     ID   =  pnlCustCharge   宽度  =  275px    runat   =  server   样式  =  display:none >  
< style = margin-left:75px >
< tr >
< td >
< asp:按钮 ID = OkButton runat = server 文字 = 确定 样式 = display:none / >
< asp:按钮 ID = btnOk runat = server 文本 = 确定

OnClick < span class =code-keyword> = btnOk_Click / >
< / td >
< ; td style < span class =code-keyword> = width:10px >
< / td >
< td >
< asp:按钮 ID = CancelButton runat = server 文本 = 重置

OnClick = btnCancelRates_Click / >
< / td >
< td style = width:10px >
< / td >
< td >
< asp:按钮 ID = ResetButton runat = 服务器 文字 = 标准

< span class =code-attribute> OnClick = btnReset_Click / >
< / td >
< / tr >
< span class =code-keyword>< / table >
< / asp:Panel >
< br / >
< cc1:ModalPopupExtender ID = ModalPopupExtender1 runat = server TargetControlID = btnCustCharges

PopupControlID = pnlCustCharge BackgroundCssClass = modalBackground DropShadow = true

EnableViewState = true OkControlID = OkButton OnOkScript = onOk()

/ >


Using the answer in my previous question, "ModalPopupExtender: Popup Closes After TextChanged Method of Textbox FIres", I was able to get the popup to work as intended as a stand-alone form including the addition of a third button to the "modal popup":

<asp:Button ID="btnReset" runat="server" Text="Standard" OnClick="btnReset_Click"/>


However when I add the relative code an existing website, I receive the following error:

"Error: Unable to get property 'click' of undefined or null reference".

The website uses a master page and the modal popup panel is within two panels, all of which is surrounded by an update panel on a tab panel. What would prevent execution of the onclick code of the new button? Is there another method to executing the code?

I only have javascript for the Ok and Cancel button of the popup (none for the Reset):

    <script type="text/javascript">
        function onOk() {
            document.getElementById('btnOk').click();
        }

        function onCancel() {
            document.getElementById('btnCancelRates').click();

        }
    </script>

How would I call the onclick code for the new button?

解决方案

Found the solution. I removed the JS for the OnCancel. removed the CancelControlID and OnCancelScroipt from the ModalPopupExtendedupdates, and used OnClick events for Reset and Cancel buttons. The Ok button uses the JS,

<asp:Panel ID="pnlCustCharge" Width="275px" runat="server" Style="display: none">
    <table style="margin-left: 75px">
        <tr>
            <td>
                <asp:Button ID="OkButton" runat="server" Text="OK" Style="display: none"/>
                <asp:Button ID="btnOk" runat="server" Text="OK"

                     OnClick="btnOk_Click"/>
            </td>
            <td style="width: 10px">
            </td>
            <td>
                <asp:Button ID="CancelButton" runat="server" Text="Reset"

                OnClick="btnCancelRates_Click" />
            </td>
            <td style="width: 10px">
            </td>
            <td>
                <asp:Button ID="ResetButton" runat="server" Text="Standard"

                    OnClick="btnReset_Click" />
            </td>
        </tr>
    </table>
</asp:Panel>
<br />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnCustCharges"

    PopupControlID="pnlCustCharge" BackgroundCssClass="modalBackground" DropShadow="true"

    EnableViewState="true" OkControlID="OkButton" OnOkScript="onOk()"

    />


这篇关于无法获取未定义或空引用的属性“单击”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆