470,595 Members | 1,615 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,595 developers. It's quick & easy.

MasterPage inheriting a MasterPage... is it possible?

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
Sep 26 '06 #1
2 2405
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" <No*************************@NoSpAm.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
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

Sep 26 '06 #2
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
Sep 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Keith Patrick | last post: by
9 posts views Thread by Leffe Andersson | last post: by
3 posts views Thread by Alex Maghen | last post: by
10 posts views Thread by Christophe Peillet | last post: by
2 posts views Thread by =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.