Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 25th, 2014, 11:32 AM
Registered User
Points: 29, Level: 1
Points: 29, Level: 1 Points: 29, Level: 1 Points: 29, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2014
Location: Bristol, UK
Posts: 7
Thanks: 5
Thanked 0 Times in 0 Posts
Default Chapter 6: Try It Out p243: it's working, but...

I've just completed the Try It Out p243 Chapter 6.

However, when I had <pages theme="Monochrome" /> in web.config, the theme shown in the browser was always Monochrome: I could select DarkGrey from the drop down, close the browser. then re-open the browser and it had "remembered" to select DarkGrey via the cookie. But the theme actually used was Monochrome.

Then I tried changing Web.config so that it had <pages theme="DarkGrey" />.
Saved that, and suddenly i could select whichever theme I wanted from the drop down and it would change the theme used on the browser.
Also it "remembered" which theme was last used via the cookie.

So...why does it work when web.config has <pages theme="DarkGrey" /> but not when it has <pages theme="Monochrome" /> ?

I have been comparing my code with what I could download from Wrox, but to no avail. I am confused at the moment!

Richard

PS: The relevant code follows:

Web.config
code
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<pages theme="Monochrome" />
<compilation debug="false" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />

</system.web>
</configuration>
/code


Default.aspx
<code>
<%@ Page Title="Welcome to Planet Wrox" Language="VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<h1>Hi there visitor and welcome to Planet Wrox</h1>
<p class="Introduction">
We're glad you're paying a visit to <a href="http://www.PlanetWrox.com">www.PlanetWrox.com</a>, the coolest music community site on the Internet.
</p>
<p class="Introduction">
Feel free to have a <a href="Default.aspx">look around</a>; there are lots of interesting <strong>reviews and concert pictures</strong> to be found here.
</p>
<p>
You can <a href="Login.aspx">log in</a> here</p>
</asp:Content>
</code>

Default.aspx.vb
<code>

Partial Class _Default
Inherits BasePage

End Class
</code>

MasterPages > Frontend.master
<code>
<%@ Master Language="VB" CodeFile="Frontend.master.vb" Inherits="MasterPages_Frontend" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<script src="/Scripts/modernizr-2.6.2.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="PageWrapper">
<header><a href="/"></a></header>
<nav>Menu Goes Here</nav>
<section id="MainContent">
<asp:ContentPlaceHolder ID="cpMainContent" runat="server">
</asp:ContentPlaceHolder>
</section>
<aside id="Sidebar">
Select a Theme:<br />
<asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True">
<asp:ListItem>Monochrome</asp:ListItem>
<asp:ListItem>DarkGray</asp:ListItem>
</asp:DropDownList>

</aside>


<footer>Footer Goes Here</footer>
</div>
</form>
</body>
</html>
</code>

MasterPages > Frontend.master.vb
<code>
Partial Class MasterPages_Frontend
Inherits System.Web.UI.MasterPage

Protected Sub ThemeList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ThemeList.SelectedIndexChanged
Dim preferredTheme As HttpCookie = New HttpCookie("PreferredTheme")
preferredTheme.Expires = DateTime.Now.AddMonths(3)
preferredTheme.Value = ThemeList.SelectedValue
Response.Cookies.Add(preferredTheme)
Response.Redirect(Request.Url.ToString())
End Sub

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim selectedTheme As String = Page.Theme
Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
If preferredTheme IsNot Nothing Then
selectedTheme = preferredTheme.Value
End If
If Not String.IsNullOrEmpty(selectedTheme) Then
Dim item As ListItem = ThemeList.Items.FindByValue(selectedTheme)
If item IsNot Nothing Then
item.Selected = True
End If
End If
End If
End Sub
End Class
</code>


App_Code > BasePage.vb
<code>
Imports Microsoft.VisualBasic

Public Class BasePage
Inherits System.Web.UI.Page

Private Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
If String.IsNullOrEmpty(Me.Title) OrElse Me.Title.Equals("Untitled Page", StringComparison.CurrentCultureIgnoreCase) Then
Throw New Exception("Page title cannot be ""Untitled Page"" or an empty string.")
End If
End Sub

Private Sub Page_PreInit(sender As Object, e As EventArgs) Handles Me.PreInit
Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
If preferredTheme IsNot Nothing Then
Dim folder As String = Server.MapPath("~/App_Themes/" & preferredTheme.Value)
If System.IO.Directory.Exists(folder) Then
Page.Theme = preferredTheme.Value
End If
End If
End Sub

End Class
</code>

App_Themes > DarkGrey > DarkGrey.css
<code>
*
{
/*
Defines the main font used throughout the entire site.
*/
font-family: Verdana, Arial, Sans-Serif;
}

body
{
/*
Clears white space around the body and sets the background color to a dark grey.
*/
margin: 0;
background-color: #565656;
}

a
{
/*
Clears the underline on normal links, and gives them #FE601A (orange) as the text color.
*/
color: #FE601A;
text-decoration: none;
}

a:hover
{
/*
Underlines links when the user hovers the mouse over them.
*/
text-decoration: underline;
}

h1
{
/*
Makes h1 elements smaller than their browser default.
*/
font-size: 20px;
}

header
{
/*
Sets the background of the header to the same color as the right-hand side of the
header image. This way, the header can expand to the right.
The margin at the bottom creates some room between the header and the menu and the main content.
*/
background-color: #E34600;
margin-bottom: 20px;
}

header a
{
/*
The header a is nested in the header. It provides a link to the homepage,
and sets the header image background.
*/
background-image: url(Images/Header.jpg);
background-repeat: no-repeat;
width: 944px;
height: 138px;
display: block;
}

nav
{
/*
Floats the entire menu on the left of the content.
*/
width: 130px;
float: left;
padding: 10px;
padding-top: 0; /* Reset the top-padding. The first menu item (home) already adds some padding to its top to create room between the nav element and the first menu item */
background-color: #F8F4EF;
margin-left: 35px;
margin-right: 20px;
font-size: 0.8em;
}

.FirstLevelMenuItems
{
padding-top: 10px;
}

section#MainContent
{
/*
Defines the main content area. The text color is white (on the gray background set on the body).
The #MainContent section element has a minimum height of 370 pixels, but can grow if necessary.
The font-size is 80% of its parent element, which in this case comes down to 80% of the font
the user has specified as the default font in the browser.
*/
color: white;
font-size: 0.8em;
width: 600px;
min-height: 370px;
padding: 10px;
float: left;
}

aside#Sidebar
{
/*
The Sidebar is positioned absolutely at the right of the page.
It has the same font-size and color as #MainContent
*/
font-size: 0.8em;
width: 124px;
color: White;
float: left;
padding-top: 10px;
}

footer
{
/*
The footer is positioned below all other content.
At the top, it gets a border with a dashed style, while all other sides have no border.
The line-height centers the text in the footer vertically.
*/
text-align: center;
border-top: 2px dashed gray;
height: 37px;
line-height: 37px;
clear: both;
background-color: #FCBB5B;
}

.Introduction
{
font-style: italic;
}
</code>


App_Themes > Monochrome > Monochrome.css
<code>
*
{
/*
Defines the main font used throughout the entire site.
*/
font-family: Arial, Sans-Serif;
}

body
{
/*
Clears white space around the body and gives it a grey background color.
*/
margin: 0;
background-color: #cccccc;
}

a
{
/*
Clears the underline on normal links, and gives them a different text color.
*/
text-decoration: none;
color: #0760B2;
}

a:hover
{
/*
Underlines links when the user hovers the mouse over them.
*/
text-decoration: underline;
}

h1
{
/*
Makes h1 elements smaller than their browser default.
*/
font-size: 20px;
}

h2
{
/*
Gives h2 elements a different background color and size,
and adds a bit of margin at the top to create room between the heading and the preceding element.
*/
font-size: 14px;
color: #7773A1;
margin-top: 10px;
}

#PageWrapper
{
/*
Sets the total width for the entire page. Also sets the background color
which is used to fill the background of the Sidebar in case the MainContent section is taller than the Sidebar.
Uses margin: auto to center the entire page in the middle of the browser's window.
*/
width: 844px;
background-color: #5487c0;
margin: auto;
}

header
{
/*
Gives the header the same width as the PageWrapper. The height creates some room for the logo
that is set with the background-image.
*/
background-image: url(Images/Header.jpg);
width: 844px;
height: 86px;
}

header a
{
/*
The header a is a link nested in header. It provides a link back to the homepage.
The size of the link is the same as the header, so the entire header is clickable.
*/
width: 844px;
height: 86px;
display: block;
}

nav
{
/*
The menu spans the page width, right below the header.
At the top and left a few pixels padding is applied to create some room.
*/
background-image: url(Images/MenuBackground.jpg);
width: 827px;
height: 36px;
padding-top: 7px;
padding-left: 17px;
}

nav a
{
/*
Links in the Menu are white. This gets overriden by styles in chapter 7.
*/
color: #fff;
}

.MainMenu
{
/*
The Menu gets a white border on all four sides.
*/
border: 1px solid #999999;
width: 814px;
height: 19px;
background-color: #555555;
}

.MainMenu ul li
{
/*
Gives the four menu items in the main menu a width of 200px each.
*/
width: 200px;
}

section#MainContent
{
/*
Defines the main content area. The #MainContent element has a minimum height of 500 pixels, but can grow if necessary.
The font-size is 80% of its parent element, which in this case comes down to 80% of the font
the user has specified as the default font in the browser.
*/
font-size: 0.8em;
width: 659px;
border-left: 1px solid white;
border-right: 2px solid white;
float: left;
background-color: #e1e1e1;
min-height: 500px;
padding: 10px;
}

aside#Sidebar
{
/*
The Sidebar is positioned to the right of the MainContent section. It gets the same font-size as the
#MainContent section and gets a background image called Sidebar.jpg.
To ensure the image is visible in (most) browsers on a small page, the element gets a minimum
height of 500px. This is ignored by IE 6.
*/
font-size: 0.8em;
color: White;
background-image: url(Images/Sidebar.jpg);
background-repeat: no-repeat;
background-color: #7773A1;
width: 142px;
min-height: 500px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 20px;
float: left;
}

footer
{
/*
The footer is positioned below all other content (yet still within PageWrapper).
clear: both is used to clear the impact of the float properties used for #MainContent and #Sidebar.
*/
width: 844px;
clear: both;
height: 37px;
background-color: #A8D5FE;
color: White;
text-align: center;
font-size: 0.7em;
font-weight: bold;
line-height: 37px;
}

.Introduction
{
font-style: italic;
color: #3e3e3e;
}

.MyButton
{
color: White;
}
</code>

Last edited by RichM-UK; July 25th, 2014 at 11:38 AM..
Reply With Quote
  #2 (permalink)  
Old July 25th, 2014, 12:17 PM
Registered User
Points: 29, Level: 1
Points: 29, Level: 1 Points: 29, Level: 1 Points: 29, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2014
Location: Bristol, UK
Posts: 7
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Imar,

It's OK - I've sussed it!

When I first changed <pages theme="Monochrome" /> I must have mis-spelled "DarkGrey" as "DarkGray"...this was then held by the cookie so later when I'd changed it to DarkGrey it didn't find a match - and gave me Monochrome.

Something like that anyway - I've made sure my spellings are consistent, have used it (so the cookie has now stored DarkGrey) and all functions OK now.

Sorry to have bothered you :)

Richard
Reply With Quote
  #3 (permalink)  
Old July 26th, 2014, 08:01 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Richard,

Good to hear you figured it out. Thanks for posting a follow up!

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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
RichM-UK (July 28th, 2014)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7 DynamicMenuItemStyle not working robbiethompson73 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 July 27th, 2011 12:45 PM
Working through Chapter 1 Geoffrey Chambers BOOK: Beginning SharePoint 2007: Building Team Solutions with MOSS 2007 ISBN: 978-0-470-12449-9 1 January 2nd, 2010 11:38 PM
Chapter 6: store not working Giorgio84 BOOK: Beginning Ruby on Rails 2 June 17th, 2007 11:17 PM
Chapter 1, First App, No, it's not working redthor BOOK: Beginning Ruby on Rails 2 February 1st, 2007 08:32 PM
Working Code for Chapter 4 clomby BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 1 December 26th, 2005 06:44 AM



All times are GMT -4. The time now is 12:58 PM.


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