Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals 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 4th, 2008, 03:49 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 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, 04:11 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

In VB.NET, unlike C#, boolean logic is not short circuited. That means that if one part of the If is False, the other part is still evaluated. In your case PreviousPage is Nothing and thus PreviousPage.IsCrossPagePostBack results in a null reference.

Try using AndAlso instead:

If Not PreviousPage Is Nothing AndAlso PreviousPage.IsCrossPagePostBack Then

Why, exactly, PreviousPage is nothing I don't know. We need to see the full source of page 1 in order to determine that.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old November 5th, 2008, 03:47 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

Thx a lot Imar, It works with "AndAlso"

http://www.workidoo.com
 
Old November 5th, 2008, 05:26 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome.

Cheers,

Imar





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
!!! 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.