MasterPage inheriting a MasterPage... is it possible?

Discussion in 'ASP .Net' started by ThunderMusic, Sep 26, 2006.

  1. ThunderMusic

    ThunderMusic Guest

    Hi,
    Maybe there is another way of doing this, but here's my problem...

    I have my web site where I have a master page to have a common layout and a
    common behavior on all my pages (that's what it's intended for)... But now
    here comes the time where some pages need some processing (like, is the user
    logged? and those kind of things)... If it was only on 1 or 2 pages, I'd
    says, i'll put it directly in the code and case closed, but there are 10-20
    pages that need this behavior while 10-15 pages don't... So I'd inherit my
    master page to include everything in the base masterpage into the new master
    page that will do the additionnal processing... and use this inherited
    master page in the pages that need the extra processing... Can it be done?

    I've thought of another way... that would be to create some properties in
    the master page code file and setting them in my "sub-pages" to know which
    processing to use... I can set these properties fine in my "sub-pages" code,
    but is it possible to set a Master Page's property right in the markup like
    we do for user controls?

    thanks a lot

    ThunderMusic
    ThunderMusic, Sep 26, 2006
    #1
    1. Advertising

  2. ThunderMusic

    clintonG Guest

    I'd say you need to implement user controls and use Membership, Roles and
    Profiles to manage authentication and access control.

    <%= Clinton Gallagher
    NET csgallagher AT metromilwaukee.com
    URL http://clintongallagher.metromilwaukee.com/
    MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

    "ThunderMusic" <> wrote in message
    news:...
    > Hi,
    > Maybe there is another way of doing this, but here's my problem...
    >
    > I have my web site where I have a master page to have a common layout and
    > a common behavior on all my pages (that's what it's intended for)... But
    > now here comes the time where some pages need some processing (like, is
    > the user logged? and those kind of things)... If it was only on 1 or 2
    > pages, I'd says, i'll put it directly in the code and case closed, but
    > there are 10-20 pages that need this behavior while 10-15 pages don't...
    > So I'd inherit my master page to include everything in the base masterpage
    > into the new master page that will do the additionnal processing... and
    > use this inherited master page in the pages that need the extra
    > processing... Can it be done?
    >
    > I've thought of another way... that would be to create some properties in
    > the master page code file and setting them in my "sub-pages" to know which
    > processing to use... I can set these properties fine in my "sub-pages"
    > code, but is it possible to set a Master Page's property right in the
    > markup like we do for user controls?
    >
    > thanks a lot
    >
    > ThunderMusic
    >
    clintonG, Sep 26, 2006
    #2
    1. Advertising

  3. ThunderMusic wrote:

    > Hi,
    > Maybe there is another way of doing this, but here's my problem...
    >
    > I have my web site where I have a master page to have a common layout and a
    > common behavior on all my pages (that's what it's intended for)... But now
    > here comes the time where some pages need some processing (like, is the user
    > logged? and those kind of things)... If it was only on 1 or 2 pages, I'd
    > says, i'll put it directly in the code and case closed, but there are 10-20
    > pages that need this behavior while 10-15 pages don't... So I'd inherit my
    > master page to include everything in the base masterpage into the new master
    > page that will do the additionnal processing... and use this inherited
    > master page in the pages that need the extra processing... Can it be done?


    Yes, and I've done it successfully.

    Master pages by default inherit from System.Web.UI.MasterPage. You can create a
    custom class that inherits MasterPage, then use the Inherits attribute in the
    <%@Master %> tag to base the master page on your custom class. You can then
    reference the public methods and properties of the new class through the client
    page's Master property. In, say, the client page's PreRender event, you might
    have this code:

    Dim MyMP as TechBear.Web.MasterPage = CType(Me.Master, TechBear.Web.MasterPage)

    If MyMP IsNot Nothing Then
    MyMP.Property1 = "This value"
    MyMP.ListOfMyObjects.Add(New MyObject("value", 1))
    MyMp.CallThisMethod()
    End If

    I have a MasterPage class that does all kinds of nifty things, like set a title,
    subtitle and list of "see also" links at the top of the page, display or not
    display a logout and print button, place page styles and javascripts into the
    header block (meaning my pages will validate properly), and a few other useful
    tricks.

    For items that have no bearing on the master page itself, you migh consider
    creating a custom class that inherits System.Web.UI.Page, which is the base
    class for a client page. I have one of those, too, with functions that retrieve
    page parameters, handles cookies, as well as properties that give access to my
    custom MembershipProvider object and, if the user is logged in, to an instance
    of my custom MembershipUser object with data on the logged in user. Again, just
    add the Inherits attribute to the <%@Page %> tag; then you can use those custom
    methods and properties through the page's Me object, so

    If Me.MyUser.HasExecutiveRole Then...

    or simply

    If MyUser.HasExecutiveRole Then...

    --
    Gregory Gadow
    Gregory Gadow, Sep 27, 2006
    #3
    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. Keith Patrick

    Possible to cache MasterPage on the client?

    Keith Patrick, Nov 21, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,642
    Keith Patrick
    Nov 21, 2005
  2. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    MasterPage -> Page -> MasterPage Code Access

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,864
    Steven Cheng[MSFT]
    Apr 14, 2006
  3. Randy Smith
    Replies:
    9
    Views:
    407
    Mark Rae
    Apr 14, 2007
  4. mr t
    Replies:
    0
    Views:
    384
  5. Torben Laursen
    Replies:
    4
    Views:
    564
    clintonG
    Mar 15, 2008
Loading...

Share This Page