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 February 16th, 2011, 02:21 PM
Authorized User
 
Join Date: Feb 2011
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default ChP 6 - Themes not switching

Have tried everything in this but just cannot get the site to switch themes.

When i reset the Web.Config value from one to the other, page uploads as per theme.

<pages theme="Monochrome" styleSheetTheme="Monochrome">
DropDownList has Auto postback set to True etc.....and can see the page flicker when selecting one of the two options.....

Running XP (SP3) I.E. (v8)

Any help appreciated.
 
Old February 16th, 2011, 02:28 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,

Can you post the relevant code for the following items:

1. Code Behind of the Master Page


2. Markup of the Master Page


3. The Base Page

4. Code behind of the page you're testing this on

Also, try removing the styleSheetTheme attribute from the web.config.

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 February 16th, 2011, 02:55 PM
Authorized User
 
Join Date: Feb 2011
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi there,

Can you post the relevant code for the following items:


1. Code Behind of the Master Page
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

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;
}
}
switch (Page.Theme.ToLower())
{
case "darkgrey":
Menu1.Visible = false;
TreeView1.Visible = true;
break;
default:
Menu1.Visible = true;
TreeView1.Visible = false;
break;
}
}


protected void lstPreferredTheme_SelectedIndexChanged1(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());
}
}


2. Markup of the Master Page
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div id="PageWrapper">
<div id="Header"><a class="HeaderLink" href="~/" runat="server"></a></div>
<div id="MenuWrapper">
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource2" CssClass="MainMenu"
Orientation="Horizontal" StaticEnableDefaultPopOutImage="False">
<StaticMenuItemStyle CssClass="StaticMenuItemStyle" />
<StaticHoverStyle CssClass="StaticHoverStyle" />
<StaticSelectedStyle CssClass="StaticSelectedStyle" />
<DynamicMenuStyle CssClass="DynamicMenuItemStyle" />
<DynamicHoverStyle CssClass="DynamicHoverStyle" />
</asp:Menu>
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource2"
ShowExpandCollapse="False">
</asp:TreeView>
<asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server"
ShowStartingNode="False" />
</div>
<div id="MainContent">
<asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator="|"></asp:SiteMapPath><br /><br />
<asp:ContentPlaceHolder ID="cpMainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="Sidebar">
Select a Theme
<asp:DropDownList ID="lstPreferredTheme" runat="server" AutoPostBack="True"
onselectedindexchanged="lstPreferredTheme_Selected IndexChanged1">
<asp:ListItem>Monochrome</asp:ListItem>
<asp:ListItem>DarkGrey</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<WROX:Banner ID="Banner1" runat="server" DisplayDirection="Vertical"/>
</div>
<div id="Footer">Footer Goes Here</div>
</div>
</form>
</body>
</html>



3. The Base Page
using System;
using System.Web;

public class BasePage : System.Web.UI.Page
{
private void Page_PreInit(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("PeferredTheme");
if (preferredTheme != null)
{
Page.Theme = preferredTheme.Value;
}
}

private void Page_PreRender(object sender, EventArgs e)
{
if (this.Title == "Untitled Page")
{
throw new Exception("Page title cannot be \"Untitled Page\".");
}
}

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

}



4. Code behind of the page you're testing this on
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}

}



Also, try removing the styleSheetTheme attribute from the web.config.

Tried this too but didnt work, have replaced it for time being as it looks more helpful in 'Design' Mode.
Cheers,

Imar
As above Imar.
 
Old February 16th, 2011, 03:27 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,

Take a look at this line in your Base Page:

Code:
 
HttpCookie preferredTheme = Request.Cookies.Get("PeferredTheme");
You're missing an r in peferred....

For any future posts, when you post code, can you use the Code button (#) on the post editor's toolbar? Makes your code a little easier to read.

Hope this helps,

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 February 16th, 2011, 07:52 PM
Authorized User
 
Join Date: Feb 2011
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Doh!....what an idiot.

Apologies had a look p2p.* site and picked up on this.
Will adhere to requirements for future posts.

Thanks for your help.
 
Old February 17th, 2011, 03:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Will adhere to requirements for future posts.
Your post was fine. It's just that this forum has a few very annoying bugs that either remove or add spaces at will, causing code to break when not wrapped in code tags.... ;-)

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!





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
Switching To entity framework luckystar BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 July 31st, 2009 09:52 PM
Switching TableAdapters striker9 ASP.NET 2.0 Basics 3 March 29th, 2006 11:11 AM
Problems with printer switching Sara Access VBA 0 December 20th, 2004 07:29 AM





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