loading data into session: will it be there
I have a master page with the following code:
protected void Page_Init(object sender, EventArgs e)
{
if (Session["SessionUserPreferences"] == null)
{
MyHelper.LoadInitialUserData(6);
}
}
In my code behind, I use some of the data that's loaded in SessionUserPreferences to display the page in the Page_Load event. The Page_Init event of the master page comes before the Page_load event of the aspx page so in theory the data should be in the session when I reach the code behind开发者_StackOverflow. But is that always going to be the case? Can the time needed to load the data from the DB be greater than the time the Page_load event will trigger? I'm using InProc Session.
Thanks.
Page_Load wont execute until Page_Init finishes. You should still check if it is null in Page_Load though.
FYI, Order of events MSDNx
So to answer your question: If the master page's init event is firing, then the rest of the master and children events will fire in sequential order as described in the article link above...
精彩评论