Call (show) a modal popup located in MasterPage from it's childs
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.
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.
Add a method to your Master page. For example:
public void ShowMpSignup4free()
{
mpSignup4free.Show();
}
Then call this method from the code behind page like this:
protected void lbSignin_Click(object sender, EventArgs e)
{
MasterPages_WebMasterPage wm = (MasterPages_WebMasterPage)(this.Master);
wm.ShowMpSignup4free();
}
Here mpSignup4free is ID of ModelPopupExtender and MasterPages_WebMasterPage is name of master page (WebMasterPage is name of master page placed in folder MasterPages. That is why the complete name of master page is MasterPages_WebMasterPage).
and lbSignin is Link button on the page whose master page is WebMasterPage to whose click event will show the model popup.
For avoiding post back place the lbSignin link button in UpdatePanel...
精彩评论