Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Master Page Page_Load not running
Message
From
20/08/2010 09:04:00
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
19/08/2010 20:39:31
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01477409
Message ID:
01477529
Views:
22
>>>>>>>Hi,
>>>>>>>
>>>>>>>I have a Master page where I put some code in the page_load in the code behind file. I also have code in the page_load of the content pages. How come the code in the master file does not run?
>>>>>>>
>>>>>>>What I am trying to do is programmatically set the Text of a label on the master page, every time any page based on this master page is displayed.
>>>>>>
>>>>>>Hmmm, it should work. Can you post the Page_Load event code from your Master page? Have you set your breakpoint in that method to make sure it truly wasn't running?
>>>>>
>>>>>I just set a breakpoint in the child page_load and followed it through. It never ran the code in my IASLeftNav.Master, but it ran the code in my IASOuter.Master which is set as the master page for my IASLeftNav.Master. Shouldn't it have still run the code in my LeftNav one?
>>>>
>>>>Sounds like it's a nested master page? (Might be a dumb question, but I have limited experience with nested master pages)
>>>>
>>>>Regardless, it should run all page load. Let me do some brainstorming and see what I can come up with...
>>>
>>>Yes, it's a nested master page. I've worked around it for now using the outer master page, but am still very interested in working out why the "middle" master page's code did not run.
>>
>>Frank,
>>
>>I think you need to add a virtual path to your content page to get access to the master then you can set the value of the label using a property. Try something like this:
>>
>>Add this to the content page source
>>< % @ MasterType virtualpath="~/IASLeftNav.master" % >
>>
>>Then add a property in the master page code behind that sets the value of the label for you
>>public string SetMyLabel
>>{
>>     set { this.lblMyLabel.Text = value; }
>>}
>>
>>Now in your content you can use something like this
>>Master.SetMyLabel("What I want to Display");
>>
>>
>>
>>That should get you started.
>>Tim
>
>Hi Tim,
>
>no, that's not what I am trying to do. I don't want to have to add this code to every page. I want some code that I put in the master page's page_load to run, but it is not. Shouldn't it?

What is the code you want to run in the Master? I thought you were trying to make dynamic changes to a control in the master page.
The only code above you would need to put in your content is the page directive so you can get to the master (because the master is a child of the content page) and then you can call properties or raise events on the master.

The master page load event will run after the content page load event. The master actually becomes a child object to the content page. The page_init on the other hand will run in the other direction. It is an issue of what you are trying to accomplish to understand how to best implement this. You may want to consider an event if you are trying to get the master page to perform based on something happening in the content page.
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform