How do you call master page methods from a content page when the button is inside an update panel?
Solution 1
I ended up just sucking it up and putting the script manager on the master page and putting the label on the master page inside an update panel.
Solution 2
I think it's a bit late , but for those who are looking for the solution,
Assuming your master page class like:
public MyMAsterPage: MasterPage
{
public void ShowMessage(string Message)
{
// DO SOMETHING
}
}
from your content page you can easily call any public method as follow:
(this.Master as MyMasterPage).ShowMessage("Some argument");
Solution 3
Function which define in masterpage:
public void Mesaj(string msj)
{
lbl_Mesaj.Text = msj;
}
Function which define in content page
protected void Page_Load(object sender, EventArgs e)
{
MasterPageWeb master = (MasterPageWeb)this.Master;
master.Mesaj("www.zafercomert.com");
}
You can call masterpage's function from content page like this.
Solution 4
<%@ MasterType VirtualPath="~/masters/SourcePage.master" %>
Master.Method(); (in code behind)
Jason
Updated on July 24, 2022Comments
-
Jason almost 2 years
I have a masterpage and a content page. In the content page I have a script manager and an update panel. In the update panel I want to be able to click a button which would hit a public method on the master page to show a message. This works if I don't have an update panel on the content page but is there a way to get it to work when the button is in an update panel?
Master Page:
public void ShowMessage(string Message) { lblError.Text = Message; lblError.Visible = True; }
Content Page:
Master.ShowMessage("something");
-
Jason over 13 yearsI'm already able to call the method like I noted in my question, the only thing I can't figure out is calling from an update panel. "This works if I don't have an update panel on the content page but is there a way to get it to work when the button is in an update panel?"
-
Armando Contestabile over 2 yearsThis is the best solution avoiding cast.