Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 September 29th, 2006, 01:08 AM
Authorized User
Join Date: Sep 2006
Location: mumbai, maharashtra, India.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default !!! ERROR In Wrox*PreviousPage.IsCrossPagePostBack

i'm taking my data from one page(Default.aspx) to another page(default2.aspx) on button1_Click(in default.aspx).
for that i have set the PostBackUrl of the Button1 to default2.aspx.
It is working fine.
But suppose if some one is directly trying to access default2.aspx without going through default.aspx then he should be redirected to default.aspx !!! For that i have done the following coding:-


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If PreviousPage.IsCrossPagePostBack Then
            Label1.Text = "Hello " & PreviousPage.pp_Textbox1.Text _
                           & "<br/>" & "Date Selected: " &
            PreviousPage.pp_Calendar1.SelectedDate.ToShortDate String()
End If

After doing this i set default2.aspx as my start page and then build it.But then it gives me this kind of an error:---------------------------------------

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 11:
Line 12: If PreviousPage.IsCrossPagePostBack Then
Line 13: Label1.Text = "Hello " & PreviousPage.pp_Textbox1.Text & "<br/>" & _
Line 14: "Date Selected: " & PreviousPage.pp_Calendar1.SelectedDate.ToShortDate String()

Source File: c:\inetpub\wwwroot\Examples\WebSite\Default2.aspx. vb Line: 12

it says that an object reference has not been set and shows the error on Line: 12, whereas this is the exact solution given in Wrox's Profesional Asp.net 2.0, Chapter 3, and Page 74(It was 'Page.IsCrossPagePostBack' but in errata it is corrected to 'PreviousPage.IsCrossPagePostBack')
!!! Please Help If SomeOne Knows This !!!

therez nothin\' as impossible, bcaz the word itself says : \'i\'-\'m\'-\'possible\'
Reply With Quote
  #2 (permalink)  
Old March 22nd, 2007, 09:57 AM
Registered User
Join Date: Mar 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Yea - found this problem myself too. The problem is that if you load the page from scratch (say, in a new browser window), then the PreviousPage object is empty, and the whole statement fails.

You need to verify that PreviousPage is indeed "not empty" before checking any of it's members. So, instead of:
if (PreviousPage.IsCrossPagePostBack) {
    // Do something
else {
Do this instead:
if ((PreviousPage != null) && (PreviousPage.IsCrossPagePostBack)) {
    // Do something
else {
Sorry - C# only because I'm rubbish at VB. I hope it helps someone out there anyway![code]

Reply With Quote

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
PreviousPage.IsCrossPagePostBack workidoo BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 2 January 9th, 2010 04:29 PM
PreviousPage.IsCrossPagePostBack workidoo ASP.NET 3.5 Professionals 3 November 5th, 2008 05:26 PM
PreviousPage.FindControl returns nothing dschips BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 3 March 6th, 2007 08:35 AM
Chapter 3 - Page.IsCrossPagePostBack dpereira BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 9 October 25th, 2006 07:50 AM
!!! ERROR In Wrox*PreviousPage.IsCrossPagePostBack dagad ASP.NET 2.0 Professional 0 September 28th, 2006 05:14 AM

All times are GMT -4. The time now is 12:17 AM.

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