Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 5th, 2012, 07:17 PM
Registered User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Question 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
Reply With Quote
  #2 (permalink)  
Old April 6th, 2012, 03:16 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old April 7th, 2012, 07:16 AM
Registered User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #4 (permalink)  
Old April 7th, 2012, 07:42 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, you can do it at once as you need to switch both themes and the master page in the PreInit method....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old April 7th, 2012, 11:00 AM
Registered User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old April 7th, 2012, 11:26 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old April 7th, 2012, 01:27 PM
Registered User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #8 (permalink)  
Old April 7th, 2012, 01:40 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #9 (permalink)  
Old April 7th, 2012, 01:59 PM
Registered User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #10 (permalink)  
Old April 7th, 2012, 02:14 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
General question - Master Pages, Base pages, templates and OOP. flapjack BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 May 1st, 2010 09:33 AM
Master Pages micptpuser ASP.NET 2.0 Basics 6 January 8th, 2009 04:50 AM
Master Pages Jayahar ASP.NET 3.5 Basics 1 September 2nd, 2008 04:20 PM
VB: GridView & DetailsView in Master-Child Rich57 ASP.NET 2.0 Basics 1 May 29th, 2008 07:14 AM
Master Pages, Content Pages and CSS carliviris Visual Studio 2005 0 January 8th, 2008 05:56 PM



All times are GMT -4. The time now is 08:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.