Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| 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 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 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()
Else
            Response.Redirect("Default2.aspx")
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\'
 
Old March 22nd, 2007, 09:57 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:
Code:
if (PreviousPage.IsCrossPagePostBack) {
    // Do something
}
else {
    Response.Redirect("~/Default.aspx");
}
Do this instead:
Code:
if ((PreviousPage != null) && (PreviousPage.IsCrossPagePostBack)) {
    // Do something
}
else {
    Response.Redirect("~/Default.aspx");
}
Sorry - C# only because I'm rubbish at VB. I hope it helps someone out there anyway![code]





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





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