Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | 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 Display Modes
  #1 (permalink)  
Old December 15th, 2010, 09:25 PM
Authorized User
Points: 157, Level: 3
Points: 157, Level: 3 Points: 157, Level: 3 Points: 157, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default Ch7, p254: CSS Classes not recognized

Have been doing good so far -- but following some of the changes of p254 TIO, the following CSS classes are not recognized in the master page:
HeadLink
MainMenu
StaticSelectedStyle
StaticMenuItemStyle
DynamicHoverStyle
DynamicMenuItemStyle
StaticHoverStyle

and the Errors tab indicate:
"Class or CssClass is not defined" for the above classes

and if I try to view the Default page in IE8, I get the following error:
"Object reference not set to an instance of an object"

Any suggestions?

Thanks
Reply With Quote
  #2 (permalink)  
Old December 16th, 2010, 01:47 AM
Imar's Avatar
Wrox Author
Points: 66,797, Level: 100
Points: 66,797, Level: 100 Points: 66,797, Level: 100 Points: 66,797, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,155
Thanks: 65
Thanked 1,392 Times in 1,372 Posts
Default

Hi there,

It's not a problem that VWD can't find the classses. It's just a warning. At run-time the correct style sheet will be linked (coming from the theme) so the browser will know how to deal with them.

An "Object reference not set to an instance of an object" means an error in your code somehow and is not related to missing CSS classes. Can you post the code surrounding the location of the error (the error message might mention the line nuber).

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 17th, 2010, 04:30 PM
Authorized User
Points: 157, Level: 3
Points: 157, Level: 3 Points: 157, Level: 3 Points: 157, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

The code is from the master.cs, and the exception occurs as the program is evaluating the expression in the switch line. During debug, with a break on the switch line, when I hover over on Page.Theme, the value displayed is null.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassMasterPage : System.Web.UI.MasterPage
{
protectedvoid Page_Load(object sender, EventArgs e)
{
//if not post back
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;
}
}
Reply With Quote
  #4 (permalink)  
Old December 17th, 2010, 05:16 PM
Imar's Avatar
Wrox Author
Points: 66,797, Level: 100
Points: 66,797, Level: 100 Points: 66,797, Level: 100 Points: 66,797, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,155
Thanks: 65
Thanked 1,392 Times in 1,372 Posts
Default

Hi there,

If Page.Theme is null, then you haven't:

a) Set the theme in the <pages /> element in web.config

and / or

b) set the theme programatically in the BasePage class.

Can you confirm this is the case?

BTW: if you post code, can you please do the following:

a) Paste and copy the code in Notepad before you post it in the editor to remove color coding
b) Wrap the code in code tags (using the toolbar above the editor)

Because of the (stupid) way this forum handles colored code, it becomes pretty hard to read and debug code otherwise.

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 20th, 2010, 10:13 PM
Authorized User
Points: 157, Level: 3
Points: 157, Level: 3 Points: 157, Level: 3 Points: 157, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default Ch6: Unable to switch themes programmatically

Still having problems with switching of themes.

When web.config specifies monochrome, I get monochrome theme -- and when I set web.config to DarkGrey, that's the theme I get -- but unable to switch from the browser.

Web.config is given below:
Code:
      <!--<pages theme="DarkGrey" styleSheetTheme="DarkGrey">-->
      <pages theme="Monochrome" >
       <!--<pages >-->
        <controls>
          <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </controls>
      </pages>
master page
Code:
<%@ 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></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
      <%--    the stylesheet will be used from the theme, and not from this master page as it was done originally      --%>      
      <%--    <link href="../Styles/Styles.css" rel="stylesheet" type="text/css" />      --%>
</head>
<body>
    <form id="form1" runat="server">
    <div id="PageWrapper">
         <div id="Header" ><a class="HeadLink" href="~/" runat="server">Header goes here</a></div>
         <div id="MenuWrapper">
            <asp:Menu ID="Menu1" runat="server" CssClass="MainMenu" 
               DataSourceID="SiteMapDataSource1" Orientation="Horizontal" 
               StaticEnableDefaultPopOutImage="False">
               <StaticSelectedStyle CssClass="StaticSelectedStyle" />
               <StaticMenuItemStyle CssClass="StaticMenuItemStyle" />
               <DynamicHoverStyle CssClass="DynamicHoverStyle" />
               <DynamicMenuItemStyle CssClass="DynamicMenuItemStyle" />
               <StaticHoverStyle CssClass="StaticHoverStyle" />
            </asp:Menu>
            <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" 
               ShowExpandCollapse="False">
            </asp:TreeView>
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" 
               ShowStartingNode="False" />
         </div>
         <div id="MainContent">
            <asp:ContentPlaceHolder ID="cphMainContent" runat="server">Main Content</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">&copy &reg Lanical Technlogies</div>
    </div>
    </form>
</body>
</html>
master.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
       //if not postback
       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;
          }
       }
       //execute either way: postbak or not
       switch (Page.Theme.ToLower())
       { 
          //change for "darkgrey", if selected 
          case "darkgrey":
             Menu1.Visible = false;
             TreeView1.Visible = true;
             break;
          //otherwise, initialize for "monochrome"
          default:
             Menu1.Visible = true;
             TreeView1.Visible = false;
             break;
       }
    }
    protected void lstPreferredTheme_SelectedIndexChanged(object sender, EventArgs e)
    {
       //declare and create the cookie
       HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
       //set the experation time of the cookie: 3 months
       preferredTheme.Expires = DateTime.Now.AddMonths(3);
       //write to the cookie: the user selected theme
       preferredTheme.Value = lstPreferredTheme.SelectedValue;
       //add the cookie to the cookie collection
       Response.Cookies.Add(preferredTheme);
       //redirect the request to the same page, thereby reset the theme immediately
       Response.Redirect(Request.Url.ToString());
    }
}
Thanks for your help.
Reply With Quote
  #6 (permalink)  
Old December 20th, 2010, 10:49 PM
Banned
 
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Zimmer Lawsuit Information - Zimmer Knee Replacement Lawsuits

Zimmer knee replacement
Zimmer recall
Zimmer knee
National legal help for those affected by the Zimmer knee.
Reply With Quote
  #7 (permalink)  
Old December 21st, 2010, 03:22 AM
Imar's Avatar
Wrox Author
Points: 66,797, Level: 100
Points: 66,797, Level: 100 Points: 66,797, Level: 100 Points: 66,797, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,155
Thanks: 65
Thanked 1,392 Times in 1,372 Posts
Default

Hi there,

Can you also post the code for the BasePage that sets the theme? Then the code is complete and I can try to reproduce your problem.

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
  #8 (permalink)  
Old December 21st, 2010, 01:10 PM
Authorized User
Points: 157, Level: 3
Points: 157, Level: 3 Points: 157, Level: 3 Points: 157, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default Unable to switch themes programmatically: BasePage.cs

Here is the code for the BasePage.cs:

Code:
using System;
using System.Web;
/// <summary>
/// Summary description for BasePage
/// </summary>
public class BasePage : System.Web.UI.Page
{
   public BasePage()    //BasePage constructor
   {  
      //Event handler to execute when the PreRender event is thrown: specified by programmer
      this.PreRender += new EventHandler(Page_PreRender);
   }
   //PreRender event handler
   private void Page_PreRender(object sender, EventArgs e)
   {
      if (this.Title == "" || this.Title=="Untitled Page")
      { 
         //throw new Exception("Page title cannot be \"Untitled Page\".");
         //Note how the user is notified via this exception w/ a user friendly message
         throw new Exception("Page title cannot be empty or untitled");
      }
   }
 
}
Reply With Quote
  #9 (permalink)  
Old December 21st, 2010, 02:06 PM
Imar's Avatar
Wrox Author
Points: 66,797, Level: 100
Points: 66,797, Level: 100 Points: 66,797, Level: 100 Points: 66,797, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,155
Thanks: 65
Thanked 1,392 Times in 1,372 Posts
Default

Well, that makes it easy; you're missing the part that sets the ID.

Take a look at the exercise on page 226 and further which shows you how to modify the BasePage to apply the theme.

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 21st, 2010, 06:12 PM
Authorized User
Points: 157, Level: 3
Points: 157, Level: 3 Points: 157, Level: 3 Points: 157, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default Final comments

Thanks Imar, that was a great help.

Apparently, I skipped the drill even though I did read the section because it is all colored and underlined.

A couple remaining questions:
1) What should have been my clue that I was missing some code?
(I did use the debugger, though)

2) Because in the past I used to do ASP.NET 2.0 in VB, I did not include the line to set up the connection between the event and its handler -- and suprisingly, it works anyhow.

Code:
public class BasePage : System.Web.UI.Page
{
   public BasePage()    //BasePage constructor
   {  
      //Manually setting event and its handler: page's PreRender event
      //this.PreRender += new EventHandler(Page_PreRender);
      //Manually setting event and its handler: page's PreInit event
      //this.PreInit += new EventHandler(Page_PreInit);
   }
3) I recall that in the past, using VB, in order to set up the skeleton for the event handler, one would select the object on the left drop down list, then select the event on the right -- to get the event handler skeleton -- rather than having to type the whole thing as the TIO suggested.

How would u do that in C#, in the .NET 3.5?

Thanks for all your help again,

mk
Reply With Quote
Reply


Thread Tools
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
CSS class not recognized in ContactForm.ascx avi1 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 October 11th, 2010 06:05 AM
Navigation - ch7. wingri BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 April 8th, 2008 08:29 AM
multiple CSS classes different way dk6607 CSS Cascading Style Sheets 3 December 6th, 2006 07:23 AM
not recognized nachtegaal9999 ASP.NET 1.0 and 1.1 Basics 0 April 25th, 2006 02:04 PM
Doing ch7 would u help me out? mara JSP Basics 1 November 18th, 2003 08:37 PM



All times are GMT -4. The time now is 07:16 PM.


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