Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Professional C# 4.0 and .NET 4
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 26th, 2011, 07:33 AM
Authorized User
Points: 297, Level: 5
Points: 297, Level: 5 Points: 297, Level: 5 Points: 297, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
  #2 (permalink)  
Old October 21st, 2011, 05:31 PM
Wrox Author
Points: 1,151, Level: 13
Points: 1,151, Level: 13 Points: 1,151, Level: 13 Points: 1,151, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Location: Austria
Posts: 171
Thanks: 2
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
 


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
Null Reference exception could occur... jrmrcol Visual Studio 2005 3 March 26th, 2009 02:49 PM
Null reference exception was unhandled labby C# 2005 0 April 24th, 2007 07: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 10:12 AM
NULL reference exception Dwizz VB.NET 2002/2003 Basics 3 June 21st, 2005 08:15 AM



All times are GMT -4. The time now is 03:39 PM.


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