【问题标题】:ModalPopupExtender, Object reference not set to an instance of an object error [closed]ModalPopupExtender,对象引用未设置为对象错误的实例[关闭]
【发布时间】:2012-09-28 07:52:54
【问题描述】:

我正在使用 DataList 控件中的 ASP 按钮来弹出 AjaxPopupExtender。但是会抛出以下错误:

Microsoft JScript 运行时错误:Sys.WebForms.PageRequestManagerServerErrorException:对象引用未设置为对象的实例。

标记:

<asp:HiddenField ID="ModalPopUpHidden" runat="server" />
<cc1:ModalPopupExtender ID="mdlComments" runat="server"
    CancelControlID="btnCancelComment" PopupControlID="pnlComments" 
    TargetControlID="ModalPopUpHidden" PopupDragHandleControlID="PopupHeader"
    Drag="true" BackgroundCssClass="ModalPopupBG">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlComments" Style="display: none" runat="server">
    <div class="popup_Container">
        <div class="popup_Titlebar" id="PopupHeader">
            Comment
        </div>
        <div class="popup_Body">
            <asp:TextBox ID="txtPopupComment" runat="server" MaxLength="500"
                TextMode="MultiLine" Width="200" Height="200">
            </asp:TextBox>
        </div>
        <div class="popup_Buttons">
            <asp:Button id="btnSaveComment" type="button" value="Save" 
                runat="server" Text="Save" CommandName="SaveComment" />
            <input id="btnCancelComment" type="button" value="Cancel"/>         
        </div>
    </div>
</asp:Panel>

代码隐藏:

protected void dtListBids_ItemCommand(object source, DataListCommandEventArgs e)
{
    if (e.CommandName == "Comments")
    {
        AjaxControlToolkit.ModalPopupExtender mdlComments = 
            (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("mdlComments");

        BidId = Convert.ToInt64(dtListBids.DataKeys[0]);
        mdlComments.Show();
    }
}

【问题讨论】:

    标签: c# asp.net ajax ajaxcontroltoolkit modalpopupextender


    【解决方案1】:

    由于您的 AJAX 调用失败、服务器端异常,您收到的错误与 JavaScript 有关。

    为什么不通过在调用服务器时设置断点来调试服务器端代码。通过此活动,您将确切知道异常发生的位置。

    【讨论】:

    • 我这样做了,并且 ajax 实例不为空。但是在 .Show() 上会发生此错误。
    • 那么 mdlComments 变量必须为空。这意味着 FindControl 无法找到 ModalPopupExtender 控件。您将 ModalPopupExtender 放在标记中的什么位置?
    【解决方案2】:

    我可以通过将&lt;li&gt; 标记中的标记移动到触发此弹出窗口的按钮旁边来解决此问题。

    【讨论】:

      猜你喜欢
      • 2011-07-09
      • 2012-08-31
      • 2011-11-21
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      相关资源
      最近更新 更多