Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > MasterPage inheriting a MasterPage... is it possible?

Reply
Thread Tools

MasterPage inheriting a MasterPage... is it possible?

 
 
ThunderMusic
Guest
Posts: n/a
 
      09-26-2006
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


 
Reply With Quote
 
 
 
 
clintonG
Guest
Posts: n/a
 
      09-26-2006
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 432'17"N 882'37"W : 432'17"N 882'37"W

"ThunderMusic" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Gregory Gadow
Guest
Posts: n/a
 
      09-27-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing a control on a masterpage that uses a second masterpage Torben Laursen ASP .Net 4 03-15-2008 03:27 AM
Masterpage change its masterpage mr t ASP .Net 0 08-29-2007 10:11 PM
MasterPages - take plain form, add MasterPage. MasterPage does NOT appear when run Randy Smith ASP .Net 9 04-14-2007 09:06 AM
MasterPage -> Page -> MasterPage Code Access =?Utf-8?B?QWxleCBNYWdoZW4=?= ASP .Net 3 04-14-2006 12:34 PM
Inheriting local variables from a common source? Wayne J ASP .Net 2 10-24-2003 05:59 PM



Advertisments