Checking to see what page is loaded from inside a master page file?

Discussion in 'ASP .Net' started by Sunfire, Nov 5, 2007.

  1. Sunfire

    Sunfire Guest

    Is there a way you can test what page is loaded from inside a master page?
    What I need to do is test to see what page is loaded inside the master page
    and then gray out the root item linked to that page in the Menu control.
    I.e. I have a root item called home. When a person is on the home page I
    want it to be disabled. Any way to do this?
     
    Sunfire, Nov 5, 2007
    #1
    1. Advertising

  2. "Sunfire" <> wrote in message
    news:...

    > Is there a way you can test what page is loaded from inside a master page?
    > What I need to do is test to see what page is loaded inside the master
    > page and then gray out the root item linked to that page in the Menu
    > control. I.e. I have a root item called home. When a person is on the home
    > page I want it to be disabled. Any way to do this?


    You're confusing MasterPages with framesets...

    A MasterPage doesn't load the content page - it's the other way round...

    When a content page loads, it interrogates its MasterPage property and then
    combines itself with it to create a single page. In fact, a MasterPage is
    just a UserControl...

    It's simple enough to get a content page to modify its MasterPage, however -
    you can create a property on the MasterPage for the content page to set, or
    you can do something like:

    ((Menu)this.Master.FindControl("MyMenu"))........


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Nov 5, 2007
    #2
    1. Advertising

  3. RE: Checking to see what page is loaded from inside a master page file

    as stated the master page is a control on the actual page. so to get the name
    its just:

    var name =
    Page.GetType().ToString().Replace("ASP."").Replace("_aspx",".aspx");

    or using request:

    var name = Path.GetFileName(Request.FilePath);

    -- bruce (sqlwork.com)


    "Sunfire" wrote:

    > Is there a way you can test what page is loaded from inside a master page?
    > What I need to do is test to see what page is loaded inside the master page
    > and then gray out the root item linked to that page in the Menu control.
    > I.e. I have a root item called home. When a person is on the home page I
    > want it to be disabled. Any way to do this?
    >
    >
    >
    >
     
    =?Utf-8?B?YnJ1Y2UgYmFya2VyIChzcWx3b3JrLmNvbSk=?=, Nov 5, 2007
    #3
  4. Sunfire

    Sunfire Guest

    ((Menu)this.Master.FindControl("MyMenu"))........
    Just one more question. Does the above line of code return a value or does
    it act like a control?
     
    Sunfire, Nov 5, 2007
    #4
  5. "Sunfire" <> wrote in message
    news:...

    > ((Menu)this.Master.FindControl("MyMenu"))........
    > Just one more question. Does the above line of code return a value or does
    > it act like a control?


    Strictly speaking, it sets a reference to a control on the MasterPage and
    casts it to the correct type - thereafter, you can modify its properties
    etc...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Nov 5, 2007
    #5
  6. Sunfire

    Sunfire Guest

    Hi... I found my answer... the code below helped me out. Somebody on this
    thread had given it to me and it works. Don't remember their name though...

    var name = Path.GetFileName(Request.FilePath);

    "Mark Rae [MVP]" <> wrote in message
    news:...
    > "Sunfire" <> wrote in message
    > news:...
    >
    >> ((Menu)this.Master.FindControl("MyMenu"))........
    >> Just one more question. Does the above line of code return a value or
    >> does it act like a control?

    >
    > Strictly speaking, it sets a reference to a control on the MasterPage and
    > casts it to the correct type - thereafter, you can modify its properties
    > etc...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Sunfire, Nov 5, 2007
    #6
  7. Sunfire

    Dave Bush Guest

    Just wrote about this. Rather than redo the entire article, here's the
    link:
    http://blog.dmbcllc.com/2007/11/05/how-to-properly-access-controls-in-th
    e-master-page/

    It talks about accessing a TD in the master page from the aspx page.
    You could do something similar to set your menu. We do it all the time.
    Even have one app where the background color of the screen changes based
    on the page you are on.

    -----Original Message-----
    From: Mark Rae [MVP] [mailto:]
    Posted At: Monday, November 05, 2007 11:27 AM
    Posted To: microsoft.public.dotnet.framework.aspnet
    Conversation: Checking to see what page is loaded from inside a master
    page file?
    Subject: Re: Checking to see what page is loaded from inside a master
    page file?

    "Sunfire" <> wrote in message
    news:...

    > Is there a way you can test what page is loaded from inside a master

    page?
    > What I need to do is test to see what page is loaded inside the master


    > page and then gray out the root item linked to that page in the Menu
    > control. I.e. I have a root item called home. When a person is on the

    home
    > page I want it to be disabled. Any way to do this?


    You're confusing MasterPages with framesets...

    A MasterPage doesn't load the content page - it's the other way round...

    When a content page loads, it interrogates its MasterPage property and
    then
    combines itself with it to create a single page. In fact, a MasterPage
    is
    just a UserControl...

    It's simple enough to get a content page to modify its MasterPage,
    however -
    you can create a property on the MasterPage for the content page to set,
    or
    you can do something like:

    ((Menu)this.Master.FindControl("MyMenu"))........


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Dave Bush, Nov 5, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo Birnbach [MS]
    Replies:
    0
    Views:
    3,355
    Marcelo Birnbach [MS]
    Jun 28, 2003
  2. Udo Corban
    Replies:
    0
    Views:
    3,913
    Udo Corban
    Jan 23, 2004
  3. Doug McCann
    Replies:
    1
    Views:
    1,101
    William Brogden
    Aug 5, 2004
  4. Frances Del Rio

    checking for what file loaded in a frame..

    Frances Del Rio, Dec 14, 2004, in forum: Javascript
    Replies:
    12
    Views:
    165
    Dr John Stockton
    Dec 16, 2004
  5. Ray Muforosky
    Replies:
    8
    Views:
    122
    Uri Guttman
    Jun 5, 2006
Loading...

Share This Page