views:

192

answers:

1

I'm trying to make a default modal box that must be accessible from any part of the application, and need to be called whenever I want from inside any page. (must be called from code-behind).

So I came up with the idea of a Panel + modalPopupExtender placed in the MasterPage, and calling it from child pages via code-behind.

How can I do that? Or perhaps you guys have a better idea to solve this.

+1  A: 

Since the modal is to be called from the code behind, you can achieve it like this

Add a method to your Master Page

public class MyMaster : MasterPage
{
     public void ShowModal(string someParameter)
     {
          // Do your logic here
          // Show the modal
     }
}

Then add a method to your page, or page base like this...

public void ShowModal(string someParameter)
{
     MyMaster masterPage = this.Master as MyMaster;
     masterPage.ShowModal(someParameter);
}

I recommend using a base class for your pages so that you don't have to replicate the above method.

Matthew
This will surely work if i'm using a modalPopupExtender, but what if I want to show some other panel or div, using something like ajax (updatepanels wouldn't work because the triggers aren't in the same page) ?
Vitor Reis
That is true. You can create a user control that leverages shared javascript code to use AJAX to pull content and show them in a popup modal.
Matthew