0

I am using an ASP button in a DataList control to pop up an AjaxPopupExtender. However the following error is being thrown:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.

Markup:

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

Code-Behind:

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();
    }
}
Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
Sev
  • 761
  • 4
  • 16
  • 29

2 Answers2

0

The error you are getting is related to JavaScript due to failure of your AJAX call, exception at server-side.

Why don't you just debug your server-side code by setting breakpoints at the time of call to the server. By this activity you would exactly know where the exception has occurred.

Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
  • I do and the ajax instance is not null. However on .Show() this error happens. – Sev Oct 08 '12 at 05:02
  • 1
    Then mdlComments variable must be null. And this means FindControl is unable to find the ModalPopupExtender control. Where have you placed ModalPopupExtender in the markup? – Furqan Safdar Oct 08 '12 at 07:09
0

I was able to resolve this by moving the markup in <li> tag next to the button that triggers this popup.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Sev
  • 761
  • 4
  • 16
  • 29