How to call content page method from master page in ASP.NET
hi,last week i had a problem with calling the content page methods from the masterpage.After spend lot of time with google finally i fond a solution for that.The solution is...
In my case i have an ajax control toolkit html editor in my master page.When content loaded to the editor i have a method to trigger in master page.through that method i need to populate my content page.for populating content page i have a method in content page.but the problem is when the content is loaded i need to trigger the content page method.i dont know any other ways are available or not but my solution is first trigger the master page method and then trigger the content page method through that.
my master page
public partial class Falcons : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
//this is the method that will called from editor when content loaded
protected void editor_content_load(object sender, EventArgs e)
{
if (contentCallEvent != null)
contentCallEvent(this, EventArgs.Empty);
}
//create public event handler to call content page method
public event EventHandler contentCallEvent;
}
My content page
public partial class Content_seo : System.Web.UI.Page
{
protected void Page_PreInit(object sender,EventArgs e)
{
// Create an event handler for the master page's contentCallEvent event
Master.contentCallEvent += new EventHandler(Button1_Click);
}
//this is the method i want to call from my master page
protected void Button1_Click(object sender, EventArgs e)
{
}
}
Then finally add this code to your content page to strongly type the virtual path of your master page
<%@ MasterType VirtualPath="~/Falcons.Master" %>
Also i want to share some definitions with you....
1)what is Page_PreInit method?
Raised after the start stage is complete and before the initialization stage begins.
Use this event for the following:
- Check the IsPostBack property to determine whether this is the first time the page is being processed. The IsCallback and IsCrossPagePostBack properties have also been set at this time.
- Create or re-create dynamic controls.
- Set a master page dynamically.
- Set the Theme property dynamically.
- Read or set profile property values.
2)what is virtual path?
A virtual path is shorthand to represent physical paths. If you use virtual paths, you can move your pages to a different domain (or server) without having to update the paths.
Comments
Post a Comment