【问题标题】:ASP.NET AJAX $find always returns null in usercontrolASP.NET AJAX $find 在用户控件中总是返回 null
【发布时间】:2011-03-23 03:09:05
【问题描述】:

我想通过我的 ModalPopUp 扩展器使用多个目标。我的一个按钮在 ModalPopup 中设置为目标,另一个将使用服务器端代码显示 ModalPopup。

到目前为止,这是我的 ModalPopup:

<msAjax:ModalPopupExtender ID="modalInform" runat="server" 
        BehaviorID="modalInform" 
        TargetControlID="btnSearchUsers" 
        PopupControlID="pnlInform" 
        RepositionMode="RepositionOnWindowResize" 
        BackgroundCssClass="modalWindow"
        OkControlID="linkCloseInform" />

然后我在 ASP.NET AJAX 网站上找到了this little tutorial。 但是当我在 pageLoad Javascript 函数中使用 $find("modalInform") 时(如底部教程中定义的那样),我总是收到 $find("modalInform") is null 错误。

此代码包含在用户控件中,用户控件用于 ASPX 页面,并且此 ASPX 页面使用 MasterPage。 我注意到如果我正在使用

<%= modalInform.ClientID %>

我得到一个不同的值,然后在我的 HTML 源代码中定义(可能是因为 MasterPage?)。

有人知道问题出在哪里吗?

提前致谢!

【问题讨论】:

    标签: asp.net asp.net-ajax


    【解决方案1】:

    尝试将 ClientID 与 $find 方法结合起来。

    而不是

    $find("modalInform") 
    

    试试这个

    $find('<%= modalInform.ClientID %>') 
    

    【讨论】:

    • 你得到什么错误? $find('') 是 null 还是未定义函数? Scriptmanager/ScriptmanagerProxy 注册了吗?
    • 错误:$find("ctl00_contentHolder_propDocument_modalInform") 为 null 我在 MasterPage 中添加了 ScriptManager。
    • documentGetElementById('') 是否也为空?
    • 抱歉,拼写错误:document.getElementById('')。 $find 或 document.getElementbyid 的值与生成的 html 文件中的真实 id 之间是否存在差异?
    • 就是,document.getElementById的值也是null!因为我在用户控件中使用它,所以这有什么关系吗?
    【解决方案2】:

    我尝试了下面的例子,我也遇到了同样的错误,比如 $find 返回 null。 后来我意识到,我错过了 "BehaviorID="AutoCompleteEx"" 属性。

    http://forums.asp.net/t/1323927.aspx

    并且在 $find("AutoCompleteEx") 方法中的作用就像一个魅力。

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 2012-01-23
      • 2019-01-20
      • 1970-01-01
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-08
      相关资源
      最近更新 更多