Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 December 15th, 2009, 06:30 PM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch 6 - User-Selected theme not working

Hi

I've read the posts here and tried all ways - but this swap just isn't working. Only one of the backgrounds is showing - ie the one whose name is included in the web.config page. The page is re-loading each time, but I'm only getting the one background.

I had to change the ID of the dropdown from "1stPreferredTheme" to "FirstPreferredTheme" as the program didn't seem to like it - ie line underneath in the VB page code.

I'm not getting an error.

Any ideas?

Thanks
Reply With Quote
  #2 (permalink)  
Old December 16th, 2009, 05:20 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Did you write code in the Master Page and in the BasePage? And is your page inheriting that BasePage?

BTW: it's lst as in list, not 1st as in first. Check out the errata for that (and other) changes / errors / explanations in the book,

If that doesn't help, can you post the code for the relevant code files (master page, page and BasePage)?

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
  #3 (permalink)  
Old December 16th, 2009, 04:47 PM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oops - of course btn, lst, txt (I forgot). The times new roman style of type in the book made it look like 1st - but, I should have known.


Anyway I seem to be going around in circles so here is the code -

BasePage.vb
Code:
Public Class BasePage
    Inherits System.Web.UI.Page

    Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
        If preferredTheme IsNot Nothing Then
            Page.Theme = preferredTheme.Value
        End If
    End Sub


    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles Me.PreRender
        If Me.Title = "" Then
            Throw New Exception("Page title cannot be blank.")
        End If
    End Sub
End Class

Web_config

<pages theme ="Monochrome"> (amongst other default code)


MasterPage.master.vb

Code:
Partial Class MasterPage
    Inherits System.Web.UI.MasterPage

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.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 lstPreferredTheme.Items.FindByValue(selectedTheme) IsNot Nothing Then
                lstPreferredTheme.Items.FindByValue(selectedTheme).Selected = True
            End If
        End If
    End Sub
End Class
MasterPage.master

Code:
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" 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></title>
     
</head>
<body>
    <form id="form1" runat="server">
    <div id="PageWrapper">
    <div id="Header"><a class="HeaderLink" href="~/" runat="server">Header Goes Here</a></div>
    <div id="MenuWrapper">Menu Goes here</div>
    <div id="MainContent">

        <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_SelectedIndexChanged">
                <asp:ListItem>Monochrome</asp:ListItem>
                <asp:ListItem>DarkGrey</asp:ListItem>
            </asp:DropDownList>
        </div>
        <div id="Footer">Footer Goes Here</div>
    </div>
    </form>
    
</body>
</html>
Thanks
Reply With Quote
  #4 (permalink)  
Old December 16th, 2009, 06:41 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi jenny,

That all looks pretty much like it should except for one thing:

<asp:DropDownList ID="lstPreferredTheme" runat="server" AutoPostBack="True" OnSelectedIndexChanged="lstPreferredTheme_Selected IndexChanged">

The handler setup for OnSelectedIndexChanged is not needed (as the Code Behind already defines this using the Handles keyword) and would cause the code to trigger twice. However, I don't think that's causing the problem.

Can it be the Web Form you're trying this out on? Maybe that page does not inherit BasePage so PreInit which applies the theme is never called? Can you post the code for that page too?

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
  #5 (permalink)  
Old December 17th, 2009, 08:17 AM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is default.aspx

Code:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<asp:Content ID="Content1" 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 on the Internet.</p>
<p class="Introduction">
    Feel free to have a <a href="Default.aspx">look around</a>, as there are lots of 
    interesting <b>reviews and concert pictures</b> to be found here.</p>
<p class="Introduction">
    You can <a href="Login.aspx">log in</a> here.</p>
</asp:Content>

I have just noticed that I don't seem to have much on this page anymore. No reference to HTML etc.

Last edited by jennyWren; December 17th, 2009 at 08:19 AM..
Reply With Quote
  #6 (permalink)  
Old December 17th, 2009, 08:26 AM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I remember now - I got rid of it when making the master page.
Reply With Quote
  #7 (permalink)  
Old December 17th, 2009, 08:36 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

And can you post the Code Behind for this page?

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
  #8 (permalink)  
Old December 17th, 2009, 08:55 AM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Finally works -

Within the Default.aspx.vb page I compared it to your example and found that the bit stating "Inherits BasePage" was assigned to

Code:
 Partial Class _Default
    Inherits System.Web.UI.Page
End Class
which was probably my default. I can't see it stated in the book.

Its a great example anyway. Theres always something small that causes problems - Thanks.

Last edited by jennyWren; December 17th, 2009 at 08:59 AM..
Reply With Quote
  #9 (permalink)  
Old December 17th, 2009, 09:34 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yeah, that's what I though. Normally, this is how the inheritance change looks:

Code:
 
YourPage
  System.Web.UI.Page
When you inherit BasePage, this changes to:

Code:
 
YourPage
  BasePage
    System.Web.UI.Page
That is, BasePage can do anyhting System.Web.UI.Page can. And YourPage can do anything BaseBase can.

If you leave out the BasePage, the behavior defined in that class never runs, and thus the theme is never applied.

Hope this clarifies things.

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
  #10 (permalink)  
Old December 17th, 2009, 12:39 PM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Imar,

I have the same problem as well (but in C#). Of coursed i followed every step in the book, read your comments above and also tryed to match every file in the Source folder to the Site folder (master, master.cs, default, default.cs, web.config, and BasePage). I also checked for Capital letters in the .cs files... but I have no idea what's wrong. can you please help me with that?

Thanks a lot!
Reply With Quote
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 6 pps 226-228 User Selected Theme Featheriver BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 20th, 2011 07:08 AM
(Chapter 6) applying user-selected theme in IE7 phoenixx ASP.NET 3.5 Basics 6 August 26th, 2008 09:49 AM
Chapter 6 User-Selected Theme Question jabo2099 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 August 21st, 2008 03:45 AM
VB.net 2005 User theme datagrid alex1985 Visual Studio 2005 7 September 11th, 2007 01:34 PM
Theme Selector wont pick up other theme Tawanda BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 May 4th, 2007 08:44 AM



All times are GMT -4. The time now is 10:06 AM.


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