 |
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
|
|
|
|
|

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

February 16th, 2011, 02:28 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

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

February 16th, 2011, 03:27 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

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

February 17th, 2011, 03:26 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |