shailendra
shailendra

Reputation: 205

Which Master Page Event fired on loading or after loading every content page?

On loading of every content page, I want to get content page name. So I want to know that which Master Page event is fired on every content page load ?

Upvotes: 1

Views: 3077

Answers (2)

Jason Evans
Jason Evans

Reputation: 29186

Here's a resource that might help, it states the events that ocur for ASP.NET pages:

http://weblogs.asp.net/ricardoperes/archive/2009/03/08/asp-net-page-events-lifecycle.aspx

  1. Page.OnPreInit
  2. MasterPageControl.OnInit (for each control on the master page)
  3. Control.OnInit (for each contol on the page)
  4. MasterPage.OnInit
  5. Page.OnInit
  6. Page.OnInitComplete
  7. Page.LoadPageStateFromPersistenceMedium
  8. Page.LoadViewState
  9. MasterPage.LoadViewState
  10. Page.OnPreLoad
  11. Page.OnLoad
  12. MasterPage.OnLoad
  13. MasterPageControl.OnLoad (for each control on the master page)
  14. Control.OnLoad (for each control on the page)
  15. OnXXX (control event)
  16. MasterPage.OnBubbleEvent
  17. Page.OnBubbleEvent
  18. Page.OnLoadComplete
  19. Page.OnPreRender
  20. MasterPage.OnPreRender
  21. MasterPageControl.OnPreRender (for each control on the master page)
  22. Control.OnPreRender (for each control on the page)
  23. Page.OnPreRenderComplete
  24. MasterPageControl.SaveControlState (for each control on the master page)
  25. Control.SaveControlState (for each control on the page)
  26. Page.SaveViewState
  27. MasterPage.SaveViewState
  28. Page.SavePageStateToPersistenceMedium
  29. Page.OnSaveStateComplete
  30. MasterPageControl.OnUnload (for each control on the master page)
  31. Control.OnUnload (for each control on the page)
  32. MasterPage.OnUnload
  33. Page.OnUnload

Also here is the official documentation about ASP.NET page lifecycle which goes into detail about all the events. Hopefully this will help you.

EDIT;

Hmmm, actually the above looks a bit over the top. It looks like all you need to do is - in each content page, make sure you reference the master page in the ASPX file:

<%@ MasterType virtualpath="~/Masters/Master1.master" %>

Then in the master page have a public method such as:

public void LogContentPageName(string name)
{
    // Do whatever you want with the passed name.
}

Then in the Page_Load event of the content pages you can do:

protected void Page_Load(object sender, Eventargs e)
{
    Master.LogContentPageName("Whatever");
}

Upvotes: 2

Naresh Pansuriya
Naresh Pansuriya

Reputation: 2045

Please try with below event

protected override void OnInit(EventArgs e) { //do your stuff here }

Upvotes: 0

Related Questions