In my application i have written lots of code in masterpage, which requires to be called once in application, i want masterpage to be freeze after one time loading and only content pages keep on changing.
You can create a Session variable and use that to run the master page code only once. You can initiliase the Session variable in Session_OnStart event (Global.asax). Somthing like this in your master page
if(Session["CodeHasBeenExecuted"] == "false")
{
//Your master page code which needs to run only once per user session, will come here...
Session["CodeHasBeenExecuted"] = "true";
}
You can't freeze the master page as you said. However, you can run something first time and store the results in cache, or application state and use it. Cache would be a good idea since you have dependency with it. So load the data when master page runs
first time and keep it in the cache. Later if the data changes, you can reload it.
Please Mark As Answer if it helped.
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
In my application i have written lots of code in masterpage, which requires to be called once in application, i want masterpage to be freeze after one time loading and only content pages keep on changing.
Hello,
That's not the purpose of Master pages. We use iframes to achieve the scenario you are looking for.
ramay001
Member
40 Points
33 Posts
Not to load Masterpage for each page again
Apr 09, 2012 11:08 AM|LINK
In my application i have written lots of code in masterpage, which requires to be called once in application, i want masterpage to be freeze after one time loading and only content pages keep on changing.
any help will be appriciated.
jigarbjpatel
Member
454 Points
88 Posts
Re: Not to load Masterpage for each page again
Apr 09, 2012 11:15 AM|LINK
You can create a Session variable and use that to run the master page code only once. You can initiliase the Session variable in Session_OnStart event (Global.asax). Somthing like this in your master page
if(Session["CodeHasBeenExecuted"] == "false") { //Your master page code which needs to run only once per user session, will come here... Session["CodeHasBeenExecuted"] = "true"; }adeelehsan
All-Star
18287 Points
2740 Posts
Re: Not to load Masterpage for each page again
Apr 09, 2012 11:15 AM|LINK
You can't freeze the master page as you said. However, you can run something first time and store the results in cache, or application state and use it. Cache would be a good idea since you have dependency with it. So load the data when master page runs first time and keep it in the cache. Later if the data changes, you can reload it.
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
ramiramilu
All-Star
95493 Points
14106 Posts
Re: Not to load Masterpage for each page again
Apr 09, 2012 11:44 AM|LINK
If you take a look at the page life cylce - you can effectively transfer data from master page to content page if you can plan accordingly..
PreInit - Page
Init - ChildUserControl
Init - UserControl
Init - MasterPage
Init - Page
InitComplete - Page
LoadPageStateFromPersistenceMedium - Page
ProcessPostData (first try) - Page
PreLoad - Page
Load - Page
Load - MasterPage
Load - UserControl
Load - ChildUserControl
ProcessPostData (second try) - Page
RaiseChangedEvents - Page
RaisePostBackEvent - Page
Click - Button - ChildUserControl
DataBinding - Page
DataBinding - MasterPage
DataBinding - UserControl
DataBinding - ChildUserControl
LoadComplete - Page
PreRender - Page
PreRender - MasterPage
PreRender - UserControl
PreRender - ChildUserControl
PreRenderComplete - Page
SaveViewState - Page
SavePageStateToPersistenceMedium - Page
SaveStateComplete - Page
Unload - ChildUserControl
Unload - UserControl
Unload - MasterPage
Unload - Page
JumpStart
Ruchira
All-Star
43018 Points
7031 Posts
MVP
Re: Not to load Masterpage for each page again
Apr 10, 2012 10:43 AM|LINK
Hello,
That's not the purpose of Master pages. We use iframes to achieve the scenario you are looking for.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.