Search code examples
ajaxcontroltoolkitmodalpopupextenderwebforms

Postback parent page when using an ASP.NET ModalPopup control


I have a custom UserControl that displays a modal popup (from the Ajax Toolkit). The control allows the user to add a note to a customer record which the parent page displays in a GridView.

I'm unable to force the parent page to reload the grid after the user clicks the "Add Note" button on the modal popup and closes it. The note is added to the database correctly, but I have to manually refresh the page to get it to display instead of it automatically refreshing when I save+close the popup.


Solution

  • You can use a delegate to fire an event in parent page after note is added to the database.

    // Declared in Custom Control.
    // CustomerCreatedEventArgs is custom event args.
    public delegate void EventHandler(object sender, CustomerCreatedEventArgs e);
    public event EventHandler CustomerCreated;
    

    After note is added, fire parent page event.

        // Raises an event to the parent page and passing recently created object.
        if (CustomerCreated != null)
        {
            CustomerCreatedEventArgs args = new CustomerCreatedEventArgs(objCustomerMaster.CustomerCode, objCustomerMaster.CustomerAddress1, objCustomerMaster.CustomerAddress2);
            CustomerCreated(this, args);
        }
    

    In parent page, implement required event to re-fill grdiview.

    protected void CustomerCreated(object sender, CustomerCreatedEventArgs e)
    {
        try
        {
            BindGridView();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    

    In your case, you can not use any custom event args, and use EventArgs class itself.