Hello, I want to change the page's theme in the MasterPage. I saw (from error messages) that it has to be in PreInit event. I was wondering if I can specify this in a master page? I tried it, but it wasn't triggering (set a breakpoint for the method, but it
wasn't being called). I'm using C# and I'm somewhat new... do I have to declare an event handler for the PreInit event? Thanks, Brian
Brian
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
No, you can't change the theme from the MasterPage's events, it must be done within the PreInit event and the MasterPage don't use the PreInit event. You can only do it in the PreInit event of the content page.
Personally I think this is something that needs fixing; it seems so odd that we have centralised design and layout with the master, but you that you can't set the Theme there. The solution is to create a base page class that inherits from System.Web.UI.Page
and override the OnPreInit event, setting the Theme there. You can then add the following to the web.config: All pages now automatically inherit from the new base page, where the PreInit will run and set the theme. Dave
Thanks for the info. Will the basePageType property still be supported in beta 2? I see they are bringing back class inheritance, as stated
here. Thanks.
Brian
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
I hope so, but I suspect not. I find it convenient to set the page type globally, but this doesn't fit with the explicit declaration of the base class. Anyone on the team here who is able (allowed) to clarify this? Dave
I thought as much. I like the idea of being able to globally set this. It's just a pain if you want to change the base page for an entire application; you need good search and replace, which frankly I think sucks. We've got this great feature, Themes, that
can only be set centrally if you do lots of extra work. None of this would be necessary if the master page had PreInit, although there are still situations where a base class is useful.
bmains
All-Star
29116 Points
5886 Posts
MVP
Change Themes in MasterPage
Dec 13, 2004 02:48 AM|LINK
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Change Themes in MasterPage
Dec 13, 2004 04:08 AM|LINK
MVP, ASPInsider, WCF RIA Services Insider
My Blog
Dave Sussman
All-Star
37716 Points
5005 Posts
ASPInsiders
MVP
Re: Change Themes in MasterPage
Dec 13, 2004 07:37 AM|LINK
bmains
All-Star
29116 Points
5886 Posts
MVP
Re: Change Themes in MasterPage
Dec 13, 2004 04:41 PM|LINK
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Dave Sussman
All-Star
37716 Points
5005 Posts
ASPInsiders
MVP
Re: Change Themes in MasterPage
Dec 14, 2004 08:18 AM|LINK
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Change Themes in MasterPage
Dec 14, 2004 06:04 PM|LINK
MVP, ASPInsider, WCF RIA Services Insider
My Blog
Dave Sussman
All-Star
37716 Points
5005 Posts
ASPInsiders
MVP
Re: Change Themes in MasterPage
Dec 15, 2004 08:49 AM|LINK
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Change Themes in MasterPage
Dec 15, 2004 09:43 AM|LINK
MVP, ASPInsider, WCF RIA Services Insider
My Blog