Wrox Programmer Forums
|
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
 
Old December 17th, 2013, 05:18 PM
Registered User
 
Join Date: Dec 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chap 6 - Dynamically changing Themes

OK. Going nuts here. I've double and triple checked my code to no avail. Still cannot get it to work. A second set of eyes would be helpful. I've deleted cookies and tried all browsers. No luck. Nothing happens. Page simply posts to itself again.

Help??? Thanks!


Web Config:
<pages theme="Monochrome"></pages>




BasePage.cs:

private void Page_PreInit(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("UserPreferredTheme");

if (preferredTheme != null)
{ Page.Theme = preferredTheme.Value; }
}



public BasePage()
{
this.PreRender += new EventHandler(Page_PreRender);
this.PreInit += new EventHandler(Page_PreInit);
}




FrontEnd.master:
<div id="SideBar">Select a Theme<br />
<asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True"
onselectedindexchanged="ThemeList_SelectedIndexCha nged">
<asp:ListItem>Monochrome</asp:ListItem>
<asp:ListItem>DarkGrey</asp:ListItem>
</asp:DropDownList>
</div>






FrontEnd.master.cs:

protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{

string selectedTheme = Page.Theme;
HttpCookie preferredTheme = Request.Cookies.Get("UserPreferredTheme");

if (preferredTheme != null)
{ selectedTheme = preferredTheme.Value;}

if (!string.IsNullOrEmpty(selectedTheme) && ThemeList.Items.FindByValue(selectedTheme) != null)
{ ThemeList.Items.FindByValue(selectedTheme).Selecte d = true; }

}


}



protected void ThemeList_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie preferredTheme = new HttpCookie("UserPreferredTheme");
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = ThemeList.SelectedValue;
Response.Cookies.Add(preferredTheme);
Response.Redirect(Request.Url.ToString());
}
 
Old December 17th, 2013, 05:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is the page you're testing this on inheriting BasePage? If not, the theme will never be applied.

If you post code here, can you please paste it in Notepad first and then use the Code (#) button on the toolbar to mark your code as code? That makes it easier to read.

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!
 
Old December 17th, 2013, 06:18 PM
Registered User
 
Join Date: Apr 2013
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default I revall similar issues from time to time!

I've been bitten by these matters, you check the code to the displayed code and it matches, In the end I copied the page from the downloaded source code and it worked.. I'll never know where I went wrong but I tend to re-do an example on my own demo websites to ensure I didn't do anything wrong!.

I think there's some tiny bugs within the VWD 2010, sometimes you just have to go back and press space on the code to get Intellisense to guide you in the right direction. (Ive recently upgraded to 2013 and ive finally managed to get the code to load up again!.
 
Old December 17th, 2013, 06:35 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> I think there's some tiny bugs within the VWD 2010

I am sure there are ;-) Be sure to report them on Microsoft's Connect site so they can be fixed, in 2013 or in later releases.

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!
 
Old December 18th, 2013, 10:16 AM
Registered User
 
Join Date: Dec 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi there,

Is the page you're testing this on inheriting BasePage? If not, the theme will never be applied.

If you post code here, can you please paste it in Notepad first and then use the Code (#) button on the toolbar to mark your code as code? That makes it easier to read.

Cheers,

Imar

That was the issue! Thanks. Good catch!
 
Old January 7th, 2014, 02:45 PM
Registered User
 
Join Date: Apr 2013
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
>> I think there's some tiny bugs within the VWD 2010

I am sure there are ;-) Be sure to report them on Microsoft's Connect site so they can be fixed, in 2013 or in later releases.

Cheers,

Imar
whoops , caught by the teacher!, I meant to say theres a few behavioural differences to 2013 (especially database designer)
base page, now I know where I was going wrong!, thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically Switching Themes robbiehaas BOOK: Beginning ASP.NET 4 : in C# and VB 5 January 30th, 2014 05:52 PM
Chapter 6 - Dynamically Switching Themes nudirection BOOK: Beginning ASP.NET 4.5 : in C# and VB 6 May 26th, 2013 02:41 PM
Dynamically switching themes KingJames978 BOOK: Beginning ASP.NET 4 : in C# and VB 15 April 22nd, 2012 11:16 AM
Chapter 6 dynamically swithing Themes? yantaq BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 9 January 27th, 2009 06:28 PM
Changing Themes notrosh ASP.NET 2.0 Professional 4 June 7th, 2006 12:25 PM





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