 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 5th, 2012, 07:17 PM
|
Registered User
|
|
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Switch at runtime between Child master.pages
Hi
I began reading this amazing book and I'm vary pleased with it.
I just need help with something...
I have created a Parent master.page and 2 Child master.pages that inherit from the Parent.
Each Child master.page is used to load a completely different StyleTheme to my website.
Inside my Parent master.page I have inserted a DropDownList control with the names of the 2 themes.
Now what I want to know is what code in C# can help me switch at runtime between the 2 child master.pages whenever a user clicks on the dropdownlist.
Thanks in advance
|

April 6th, 2012, 03:16 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Take a look here: http://stackoverflow.com/questions/3...es-master-page
BTW: make sure both master pages have the same set of ContentPlaceholder controls.
Cheers,
Imar
|

April 7th, 2012, 07:16 AM
|
Registered User
|
|
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I have been building my website in accordance with the teachings of the book.
The styles to my website are set from the ( App_Themes ) folder. Inside the ( App_Themes ) folder I have 2 themes – Light and Dark.
I also have 1 Parent Master.page and 2 Child master.pages and each child master.page loads a different style to the website.
I don’t know if I’m thinking right here - but is it possible to change programmatically the theme from the ( App_Themes ) and Child master.page with single DropDownList or is it only possible to change one at a time???
Thanks in advance.
|

April 7th, 2012, 07:42 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, you can do it at once as you need to switch both themes and the master page in the PreInit method....
Cheers,
Imar
|

April 7th, 2012, 11:00 AM
|
Registered User
|
|
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply mr Imar
If I may ask - Back in chapter 6 where you first start to explaine how to switch between themes, you insert some code logic inside ( Frontend.master.cs ). In your example you had only 1 Master.page.
Now in my case where I have 1 Parent and 2 children - Am I right to assume that code will go inside the parent master.page code behind and not inside one of the child master.pages.
Thanks in advance
|

April 7th, 2012, 11:26 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, that way you only have to write the code once.
Then in the BasePage you can apply the selected master page as well as the selected theme....
Imar
|

April 7th, 2012, 01:27 PM
|
Registered User
|
|
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks again for clarifying that Mr. Imar
I'm sorry to keep bothering you with this it's just that I keep have some trouble getting it to work.
So if it’s ok could you please clarify one more thing to me?
I have created 4 aspx.pages that inherit from the darktheme Child master
• Home
• About
• Work
• Contact
Is it possible to switch the inheritance of these aspx.pages from ( Dark child master.page ) to ( Light child master.page ) or must I create 4 additional aspx.pages that inherit from the light master.page?
Thanks once again
|

April 7th, 2012, 01:40 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
May I ask a question in return? Why don't you just try it out? The best way to learn is to experiment. The article I linked to showed you exactly how to switch master pages at run-time and I have provided other information in this thread of stuff you need to be aware off.
So, try it out, and you'll see that it works.
Imar
|

April 7th, 2012, 01:59 PM
|
Registered User
|
|
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I'm new to this Asp.net and it goes without saying that I will need to experiment on this as I have for hours now :)
I just thought that I might be a good idea to ask and make sure that I'm not thinking wrong while beliving that my computer is messing with me.
Thanks
|

April 7th, 2012, 02:14 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
In that case, rather than posting questions like "Can it be done?", what about posting questions like: "I have been experimenting with this and that in order to accomplish such and so. However, when I try such and so, I run into error X. Here's the relevant code I am trying to get to work, as well as the error message I am getting"
That way, it's way easier to help you figure this out ;-)
Cheers,
Imar
|
|
 |
|