Wrox Programmer Forums
|
BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9
This is the forum to discuss the Wrox book Professional ASP.NET 3.5: In C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470187579
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 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 November 2nd, 2008, 09:19 AM
Authorized User
 
Join Date: Jun 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to workidoo
Default PreviousPage.IsCrossPagePostBack

Has just started a little bit with exercises in the book and has encountered a problem already in the beginning, Listing 1-13. I always get a following error when I try to go directly to page2.aspx and not go through page1.aspx. System.NullReferenceException: Object reference not set to an instance of an object. It somplains on line 5 in my codebehind: "If Not PreviousPage Is Nothing And PreviousPage.IsCrossPagePostBack Then"

This is how my code behind on page2.aspx.vb looks like:

Public Partial Class Page2
    Inherits System.Web.UI.Page

    Private Sub Page2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not PreviousPage Is Nothing And PreviousPage.IsCrossPagePostBack Then
            Dim pp_Textbox1 As TextBox
            Dim pp_Calendar1 As Calendar

            pp_Textbox1 = CType(PreviousPage.FindControl("Textbox1"), TextBox)
            pp_Calendar1 = CType(PreviousPage.FindControl("Calender1"), Calendar)

            Label1.Text = "Hello " & pp_Textbox1.Text & "<br /> Date Selected: " & pp_Calendar1.SelectedDate.ToShortDateString()
        Else
            Response.Redirect("Page1.aspx")
        End If
    End Sub
End Class

and this is my page2.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Page2.aspx.vb" Inherits="ASPNET.Page2" %>
<%@ PreviousPageType VirtualPath="~/Page1.aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Second Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </form>
</body>
</html>


http://www.workidoo.com
__________________
http://www.workidoo.com
 
Old November 4th, 2008, 03:50 PM
Authorized User
 
Join Date: Jun 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to workidoo
Default

Why is there no one who answer questions here???

http://www.workidoo.com
 
Old January 9th, 2010, 04:29 PM
Registered User
 
Join Date: Jan 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default It's a bug in the code

Hi,

I got the same problem when I added the code in Listing 1-13. The problem is in the IF statement:

Code:
If Not PreviousPage Is Nothing And PreviousPage.IsCrossPagePostBack Then
The problem arises when PreviousPage is nothing - you cannot check IsCrossPagePostBack for an object that does not exist. I got round it by nesting IF statements...

Code:
If Not PreviousPage Is Nothing Then
  If PreviousPage.IsCrossPagePostBack Then
    Label1.Text = "Hello..."
  Else
    Response.Redirect("Page1.aspx")
  End If
Else
  Response.Redirect("Page1.aspx")
End If





Similar Threads
Thread Thread Starter Forum Replies Last Post
PreviousPage.IsCrossPagePostBack workidoo ASP.NET 3.5 Professionals 3 November 5th, 2008 05:26 PM
!!! ERROR In Wrox*PreviousPage.IsCrossPagePostBack dagad ASP.NET 2.0 Basics 1 March 22nd, 2007 09:57 AM
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.