Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion 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 June 11th, 2012, 08:31 AM
Registered User
 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default Theme Not Working In Final Page

BASE PAGE CODING:

public class BasePage : System.Web.UI.Page
{
public BasePage()
{
//
// TODO: Add constructor logic here
//
this.PreRender += new EventHandler(Page_PreRender);
this.PreInit += new EventHandler(Page_PreInit);
}

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

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


MASTER PAGE CODING:

public partial class MasterPages_FrontEnd : 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 (!string.IsNullOrEmpty(selectedTheme) &&
ThemeSelect.Items.FindByValue(selectedTheme) != null)
{
ThemeSelect.Items.FindByValue(selectedTheme).Selec ted = true;
}
}
switch (Page.Theme.ToLower())
{
case "darkgrey":
Menu1.Visible = false;
TreeView1.Visible = true;
break;
case "monochrome":
Menu1.Visible = true;
TreeView1.Visible = false;
break;
}
}
protected void ThemeSelect_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies["PreferredTheme"];
if (preferredTheme == null)
{
preferredTheme = new HttpCookie("PreferredTheme");
}
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = ThemeSelect.SelectedValue;
Response.Cookies.Add(preferredTheme);
Response.Redirect(Request.Url.ToString());
}
}


WEB.CONFIG:

<?xml version="1.0"?>

<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
<pages theme ="Monochrome"></pages>
</system.web>

</configuration>
 
Old June 11th, 2012, 08:42 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,

Take another look at the exercise on page 231. The code in Page_PreInit should access Request.Cookies, not Response.Cookies as you have....

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!
The Following User Says Thank You to Imar For This Useful Post:
Rajasekar1988 (June 12th, 2012)
 
Old June 12th, 2012, 02:05 AM
Registered User
 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to add a new sitemapnode

Hello Mr. Imar, I'm trying to add a new sitemapnode to the one we are using in Planet Wrox but wat i'm getting is the element 'X' in namespace has invalid child element in sitemapnode in namespace..
 
Old June 12th, 2012, 08:29 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,

As suggested earlier, please start a new thread for a new topic. Your last question has nothing to do with the BasePage, so a new thread with your question is a much better solution.

Also, consider using the book's own forum at: http://p2p.wrox.com/book-beginning-asp-net-4-c-vb-560/

Finally, please consider searching the forums before you post anew topic to see if someone else had the same question. In your case, the answer to your problem can be found here: Ch.7 Pg.247 - Web.sitemap

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
Working with the DarkGrey.css theme demac3 BOOK: Beginning ASP.NET 4 : in C# and VB 4 December 12th, 2010 11:30 AM
Ch6 - User Theme Selection not working ken evans BOOK: Beginning ASP.NET 4 : in C# and VB 6 October 16th, 2010 10:19 AM
Apply page theme ryanburnett BOOK: Beginning ASP.NET 4 : in C# and VB 20 September 17th, 2010 09:51 AM
Ch 6 - User-Selected theme not working jennyWren BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 16 December 21st, 2009 03:52 PM
page theme zhugeliang ASP.NET 2.0 Basics 1 January 9th, 2007 02:40 AM





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