Wrox Programmer Forums
|
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
 
Old January 24th, 2011, 12:43 PM
Authorized User
 
Join Date: Feb 2006
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default Ch12, TIO p397: Exception in execution

Following Setting Up the Filter TIO, I get the following excepton. No other errors otherwise. Can you help?

Thanks, Michael

The exception from the browser:
Quote:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:

Line 27:
Line 28: //execute either way: postbak or not
Line 29: switch (Page.Theme.ToLower())
Line 30: {
Line 31: //change for "darkgrey", if selected

Source File: d:\WroxBegASPNET35\PlanetWroxSite\MasterPages\Mast erPage.master.cs Line: 29
Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
MasterPage.Page_Load(Object sender, EventArgs e) in d:\WroxBegASPNET35\PlanetWroxSite\MasterPages\Mast erPage.master.cs:29
System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

The markup for Reviews.aspx:

Quote:
<%@ Page Title="Lanical - Management - Reviews" Language="C#"
MasterPageFile="~/MasterPages/MasterPage.master"
AutoEventWireup="true"
CodeFile="Reviews.aspx.cs"
Inherits="Management_Reviews" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMainContent" Runat="Server">

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id"
onselectedindexchanged="DropDownList1_SelectedInde xChanged"
AppendDataBoundItems="True"
AutoPostBack="true" >
<asp:ListItem Value="">Please make a selection</asp:ListItem>
</asp:DropDownList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
SelectCommand="SELECT [Id], [Name] FROM [Genere] ORDER BY [SortOrder]">
</asp:SqlDataSource>
</asp:Content>
and the corresponding Reviews.cs file:
Quote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Management_Reviews : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
The markup for the ManagementMaster.master:
Quote:
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="ManagementMaster.master.cs"
Inherits="MasterPages_ManagementMaster" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div style="width: 200px; float:left;">
<ul>
<%--"." in href was changed to "~", mk 01-23-11--%>
<li><a href="~/Management/Default.aspx" runat="server">Management Home</a></li>
<li><a href="~/Management/Generes.aspx" runat="server">Manage Geners</a></li>
<li><a href="~/Management/Reviews.aspx" runat="server">Manage Reviews</a></li>
</ul>
</div>

<div style="width: 750px; float:left;">
<asp:ContentPlaceHolder id="cpMainContent" runat="server">

</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
and last, MasterPage.master.cs:
Quote:
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());
}
}
 
Old January 24th, 2011, 12:51 PM
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,

Did you set the theme to an empty string in the web.config file in the Management folder as instructed on page 388 and 389?

If that doesn't help, can you post the code for your two web.config files?

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!
 
Old January 24th, 2011, 01:10 PM
Authorized User
 
Join Date: Feb 2006
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default code for web.config files

Here is the code:

web.config under Management folder:
Quote:
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<pages theme=""></pages>
</system.web>
</configuration>
and web.config from the application root:
Quote:
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensions SectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGro up, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptReso urceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebService sSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerial izationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileSer viceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthentica tionServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServic eSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

<appSettings/>
<connectionStrings>
<add name="PlanetWroxConnectionString1"
connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\PlanetWrox.mdf;
Integrated Security=True;
User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>

<!--uncomment next line to enable Tracing (Default: false); added by MK, 12-21-10-->
<!--<trace enabled="true" pageOutput="true"/>-->

<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"> <!--Default: false; MK set to "true" 12-16-10, must be set to "false" on production-->
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->

<!--<pages theme="DarkGrey" styleSheetTheme="DarkGrey">-->
<pages theme="Monochrome" >
<!--<pages >-->

<controls>
<add tagPrefix="Lanical" tagName="Banner" src="~/Controls/Banner.ascx" />
<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>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFact ory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFact ory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4"
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>

<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory" />
<remove name="ScriptHandlerFactoryAppServices" />
<remove name="ScriptResource" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFact ory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFact ory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network"
from="Michael Kaftor&lt;[email protected]&gt;">
<network host="smtp.live.com"
userName="[email protected]"
password="live9936"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
 
Old January 24th, 2011, 01:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Just saw something else:

<%@ Page Title="Lanical - Management - Reviews" Language="C#"
MasterPageFile="~/MasterPages/MasterPage.master"
AutoEventWireup="true"
CodeFile="Reviews.aspx.cs"
Inherits="Management_Reviews" %>

The pages in your Management section should be based on ManagementMaster.master, not on MasterPage.master

Does that fix the problem? If not, can you zip up the site and send it to me? You can find out my e-mail address by sending me a message through the Contact page of my web site: http://imar.spaanjaars.com/about to which I'll reply.

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!
 
Old January 24th, 2011, 02:54 PM
Authorized User
 
Join Date: Feb 2006
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default Exception problem resolved -- and wording error on page 395?

Thanks -- indeed I based the page on the wrong master.

And as a contribution on my part, would the 5th line from the bottom, p395, should read:
. . . for the connection string that is listed by the name PlanetWroxConnectionString1, instead of
. . . for the connection string that listens the name PlanetWroxConnectionString1,
?????

"listens" does not make sense to me???
 
Old January 24th, 2011, 04:41 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The text says "listens to". Of course it doesn't actually listen, but you can access it by using its name ;-) E.g. you call PlanetWroxConnectionString1 and you get the connection string back....

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!
 
Old January 25th, 2011, 04:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Oh, BTW: it's probably a good idea to remove your mail settings from the config file you posted here ;-)

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
Ch8 - TIO#4 (Other List Controls) jecii BOOK: Beginning ASP.NET 2.0 and Databases 0 December 7th, 2007 07:57 PM
TIO-0903-TextBoxWithLIKE tbroom BOOK: Beginning ASP.NET 2.0 and Databases 1 November 1st, 2006 04:11 PM
TIO-0904-DropDownList tbroom BOOK: Beginning ASP.NET 2.0 and Databases 0 October 13th, 2006 05:00 PM
WOW--TIO-0905 VERY confusing rsearing BOOK: Beginning ASP.NET 2.0 and Databases 9 October 12th, 2006 12:36 PM





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