Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 January 27th, 2009, 03:46 AM
Registered User
 
Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Chapter 6 dynamically swithing Themes?

Hi there!

I followed as the book instructed, and the look of the page with DarkGrey and Monochrome works fine before I add dynamically selecting code.
for the first time with cookies cleared, say my default is Monochrome, the page renders fine, but when I select the DarkGrey from the DropDownList
it automatically changes back to Monochrome and page layout overlaps.
I pasted the html source in head tags in which there are two style links.

<html xmlns="http://www.w3.org/1999/xhtml">
<head><link href="App_Themes/Monochrome/Monochrome.css" type="text/css" rel="stylesheet" /><title>
Planet Wrox
</title>
<link href="App_Themes/DarkGrey/DarkGrey.css" type="text/css" rel="stylesheet" /></head>
I am a newbie so I'd appreciate if someone help me
how i can correct it!
 
Old January 27th, 2009, 03:54 AM
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,

Looks like you still have the styleSheetTheme configured in web.config. See pages 219 and 227 (step 4 in particular):
Quote:
Choose a new item from the list. The page should reload and should now show the other theme. If you find that the page in the browser is showing a combination of the two themes, go back to VWD, open web.config, and remove the styleSheetTheme attribute from the <pages> element.
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 January 27th, 2009, 04:40 AM
Registered User
 
Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Post Thanks Spaanjaars

It worked fine, but it is only allowing me to change the Theme once from the dropdownlist control and everytime I select the other one it wouldn't allow me
it seems I have to take better look at the book tomorrow.
 
Old January 27th, 2009, 04:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you define "it wouldn't allow me"? Do you get an error? Or is the theme just not changed? And what happens when you set a breakpoint (see chapter 591) in the code and debug it? Do you see the correct code getting fired?

Finally, do the names of the themes in the DropDownList match with your actual themes?

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 January 27th, 2009, 05:27 AM
Registered User
 
Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't get any error. to be more specific, by default I set <pages theme="Monochrome">
and clear the cookie, page changes from Monochrome to DarkGrey when I select DarkGrey, but item Momochrome stays in the DropDownList text field. from that point page refreshs when I attempt to change the theme but nothing else happens. no error as well.
Thanks
 
Old January 27th, 2009, 05:38 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi again,

For this code to work, you need three pieces of information:

1. A default Theme in the <pages /> element in web.config; not a styleSheetTheme

2. Code in the BasePage class that sets the selected theme based on a cookie

3. Code in the Master Page's Code Behind to set the cookie and redirect (in lstPreferredTheme) and preselect the right item (in Pre_Init).

Do you have all that?

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 January 27th, 2009, 05:58 AM
Registered User
 
Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi again,

For this code to work, you need three pieces of information:

1. A default Theme in the <pages /> element in web.config; not a styleSheetTheme

2. Code in the BasePage class that sets the selected theme based on a cookie

3. Code in the Master Page's Code Behind to set the cookie and redirect (in lstPreferredTheme) and preselect the right item (in Pre_Init).

Do you have all that?

Imar
1. Default theme in the <pages/> element in web.config <pages theme="Monochrome">

====================================
2. Code in the BasePage is:
====================================
using System;
using System.Web;

public class BasePage : System.Web.UI.Page
{
private void Page_PreRender(object sender, EventArgs e)
{
if (this.Title == "Untitled Page")
{
throw new Exception("Page title cannot be \"Untitled Page\".");

}

}

private void Page_PreInit(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{
Page.Theme = preferredTheme.Value;
}
}

public BasePage()
{

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


}

==================================
3. This is the code snippet in the master page
==================================

public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string selectedTheme = Page.Theme;
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{
selectedTheme = preferredTheme.Value;
}
if (lstPreferredTheme.Items.FindByValue(selectedTheme ) != null)
{
lstPreferredTheme.Items.FindByValue(selectedTheme) .Selected = true;
}
}

}
protected void lstPreferredTheme_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = lstPreferredTheme.SelectedValue;
Response.Cookies.Add(preferredTheme);
Response.Redirect(Request.Url.ToString());
}
}
===========================
 
Old January 27th, 2009, 06:07 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

That all looks pretty much like it should. Couple of other questions:

1. Does your browser support cookies?

2. What happens when you set a breakpoint on the SelectedIndexChanged code and on the Pre_Init code and hit F5? Are both locations hit?

3. Is AutoPostBack set to true on the DropDownList?

4. Does the DropDownList contain the right items with the right Value and Text properties? (e.g. DarkGrey and Monochrome for each proeprty).


Tip of the day: use the CODE button on the toolbar to format code here; makes it easier to read the code you're posting....

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 January 27th, 2009, 06:55 AM
Registered User
 
Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'll post debug related info later , too late now and mind is not functioning further.
Thanks
 
Old January 27th, 2009, 06:28 PM
Registered User
 
Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Solved!

Quote:
Originally Posted by Imar View Post
That all looks pretty much like it should. Couple of other questions:

1. Does your browser support cookies?

2. What happens when you set a breakpoint on the SelectedIndexChanged code and on the Pre_Init code and hit F5? Are both locations hit?

3. Is AutoPostBack set to true on the DropDownList?

4. Does the DropDownList contain the right items with the right Value and Text properties? (e.g. DarkGrey and Monochrome for each proeprty).


Tip of the day: use the CODE button on the toolbar to format code here; makes it easier to read the code you're posting....

Imar
Answer to 1,2,3 is positive but not very sure about 4.

I replaced the code in my master page with the code in source that I downloaded, now problem has gone. I should have backed up my code so that I could check where went wrong. I did compare the code but didn't find any glitch. now it is working fine though and i can proceed to next chapter.

I really like your book.
Thanks for your support!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Applying themes to Page Try it Out mcauliff BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 October 3rd, 2007 11:04 AM
Use Themes? the.pi.man ASP.NET 2.0 Basics 2 March 7th, 2007 08:44 AM
Swithing between child windows, Like Internet Expl oceaniana General .NET 1 April 7th, 2006 06:51 AM
Themes bmains ASP.NET 2.0 Basics 2 August 2nd, 2004 08:48 AM





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