Wrox Programmer Forums
|
BOOK: Professional C# 4.0 and .NET 4
This is the forum to discuss the Wrox book Professional C# 4.0 and .NET 4 by Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner; ISBN: 9780470502259
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C# 4.0 and .NET 4 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 September 26th, 2011, 06:33 AM
Authorized User
 
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Null Reference Exception Listing 1-10

Hello All,

I just tried to use the following code from the book and received the error

Null Reference Exception was unhandled by user code.

My code is as follows.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Listing1-10.aspx.cs" Inherits="WebApplication1.Listing1_10" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e)
{
TextBox pp_TextBox1;
Calendar pp_Calendar1;

pp_TextBox1 = (TextBox)PreviousPage.FindControl("TextBox1");
pp_Calendar1 = (Calendar)PreviousPage.FindControl("Calendar1");

Label1.Text = "Hello " + pp_TextBox1.Text + "<br />" + "Date Selected " +
pp_Calendar1.SelectedDate.ToShortDateString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>


Any ideas?

Regards

Tomche
 
Old October 21st, 2011, 04:31 PM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Does the Null Reference Exception happen with the PreviousPage? Do you use this page with a previous page? If not, the PreviousPage is not set and thus FindControl fails.

I hope this helps,
Christian
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel





Similar Threads
Thread Thread Starter Forum Replies Last Post
Null Reference exception could occur... jrmrcol Visual Studio 2005 3 March 26th, 2009 01:49 PM
Null reference exception was unhandled labby C# 2005 0 April 24th, 2007 06:14 AM
Null Reference Exception was unhandled labby C# 2005 1 February 9th, 2007 03:15 PM
Null reference exception when using DataAdapter Samantha Karen Webb C# 1 July 21st, 2006 09:12 AM
NULL reference exception Dwizz VB.NET 2002/2003 Basics 3 June 21st, 2005 07:15 AM





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