Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Master Page Page_Load not running
Message
From
20/08/2010 13:51:15
 
 
To
20/08/2010 09:13:16
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01477409
Message ID:
01477624
Views:
26
>>>>>>>>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?
>
>
>Frank,
>
>this article is a bit old, but has some good descriptions on Master pages and how to reference them both directions.
>http://odetocode.com/Articles/450.aspx
>Tim

The problem I am having is with the nested master pages you created for me. I'm not sure if you have them lying around still, but this is the picture, maybe you could try it out .

I have Default.aspx which has this in it:
< %@ Page Title="" Language="C#" MasterPageFile="~/IASLeftNav.Master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="SamaanSystems.IAS.Web.CustomerManager" % >
So Default uses IASLeftNav.Master as its master.

IASLeftNav.Master has this in it:
< %@ Master Language="C#" MasterPageFile="~/IASOuter.Master" AutoEventWireup="false"
    CodeBehind="IASLeftNav.master.cs" Inherits="SamaanSystems.IAS.Web.IASLeftNav" % >
so it uses IASOuter.Master as its master.

If I step through from the Default.aspx.cs's Page_Load, the IASLeftNav.Master.Page_Load never runs, but the Page_Load in the IASOuter.Master does run. I had thought that both would run so am trying to understand why the middle one is not running.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform