Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET 4 : in C# and VB
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Professional ASP.NET 4 in C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470502204
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 4 : in C# and VB 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 Search this Thread Display Modes
  #1 (permalink)  
Old October 11th, 2011, 05:19 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 Listing 1-10 NullReferenceException was unhandled by

Hello All,

I am getting the error NullReferenceException was unhandled by user code on the Listing I.10.

The exception occurs on the TextBox1 object.

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 " +
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server"></asp:Label>

What is a null reference exception?

Why does it apply to the TextBox1 object?

Any help would be most appreciated.

Kind Regards

  #2 (permalink)  
Old February 14th, 2012, 05:29 PM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default Previous Page

Hi there

I think you're running this page directly. the source of the NullException in your sample refers to PreviousPage. it does not contains a control named 'TextBox1' so >>> (TextBox)PreviousPage.FindControl("TextBox1"); <<< return null. if you write:
string msg = ((TextBox)PreviousPage.FindControl("TextBox1")).Te xt;
You'll got the error here. NullReferenceException
happy every time, happy every where

Reza Baiat

Last edited by irProject; February 14th, 2012 at 05:32 PM..

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
System.NullReferenceException was unhandled by user code - Chapter 8 dtmmaxx BOOK: Beginning ASP.NET 4 : in C# and VB 10 September 1st, 2011 05:51 PM
nullreferenceexception was unhandled by user code rnavin BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 June 11th, 2011 09:26 AM
Chapter 10, listing 10-10-app kiwibrit BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 2 August 18th, 2009 04:21 AM
Listing 8-10 and Listing 8-16. Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 February 6th, 2008 01:11 PM
Ch. 10 Directory listing superkooi BOOK: Beginning ASP 3.0 1 March 3rd, 2005 07:39 AM

All times are GMT -4. The time now is 03:49 AM.

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