Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 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 February 13th, 2006, 08:33 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 3 - Page.IsCrossPagePostBack

Refer to code listing 3-13
Clicking Button2 on Page1.aspx, invokes Page2.aspx however Page.IsCrossPagePostBack is always false. Instead of displaying Page2.aspx the response.Redirect("Page1.aspx") is always invoked.
Can someone let me know what the fix is here.
  #2 (permalink)  
Old February 14th, 2006, 02:54 AM
AGS AGS is offline
Wrox Technical Editor
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: Russia
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi dpereira,

There is obviously an error in the code listing 3-13 and explanations above. IsCrossPagePostBack returns true for the page that originates a postback (i.e. page accessible through the PreviousPage property). Page.IsCrossPagePostBack for the current page always returns false.

http://msdn2.microsoft.com/en-us/lib...epostback.aspx
http://weblogs.asp.net/despos/archiv...12/406579.aspx

Best regards,
Alexei

  #3 (permalink)  
Old May 11th, 2006, 04:30 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm glad someone addressed this. Strange that Wrox hasn't incorporated this in the errata yet.

I am using the VB code. To get this example to work, change the highlighted line on page 74 to this:
If PreviousPage.IsCrossPagePostBack Then


Chris
Allentown, Pa.
  #4 (permalink)  
Old May 12th, 2006, 01:34 PM
jminatel's Avatar
Wrox Staff
Points: 18,940, Level: 59
Points: 18,940, Level: 59 Points: 18,940, Level: 59 Points: 18,940, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Location: Indianapolis, IN, USA.
Posts: 1,945
Thanks: 73
Thanked 139 Times in 101 Posts
Default

This will get added to the errata soon. Sorry for the delay. I had a small bundle of fixes I was gathering to submit all at once.

Jim Minatel
Senior Acquisitions Editor
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
Jim's Book of the week: No book this week - Donate to the Red Cross!
  #5 (permalink)  
Old July 3rd, 2006, 05:12 AM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah I have another issue about it. When I visit Page2.aspx directly it gives me errors.

 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.

  #6 (permalink)  
Old July 3rd, 2006, 05:13 AM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah I have another issue about it. When I visit Page2.aspx directly it gives me errors.

 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.
  #7 (permalink)  
Old July 6th, 2006, 12:51 AM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

instead of using page.isCrossPagePostBack please use previousPage.IsCrossPagePostBack. This will solve the problem.

  #8 (permalink)  
Old September 21st, 2006, 09:19 PM
Authorized User
Points: 176, Level: 3
Points: 176, Level: 3 Points: 176, Level: 3 Points: 176, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

CrossPagePostBack C# Version

Here is the BugFix. using the AND Operator. [C# code]
Page 75. Listing 3-13
[from Wrox Box Professional ASP.NET 2.0 ]
Thanks to the blog of Dino Esposito!
//-------------------------------------

protected void Page_Load(object sender, System.EventArgs e)
    {
      if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
      {
        Label1.Text = "Hello " + PreviousPage.pp_TextBox1.Text + "<br />" +
           "Date Selected: " +
           PreviousPage.pp_Calendar1.SelectedDate.ToShortDate String();
      }
      else
      {
              // if previous Page is NULL just redirect us
              Response.Redirect("Page1.aspx");

      }

    }
//-----------------------------------------------------

It Works just Fine! check it on my website http://aspspider.info/chadfunk/CrossPage/CSharp/1.aspx
If you came from Page1.aspx you will see your information on the Second page.
and if you will try to enter Page2.aspx directly, it will Redirect you to the Page1.aspx.
  #9 (permalink)  
Old October 12th, 2006, 09:01 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shysusan
Default

Does anyone have the VB code for the above solution. I have tried the C# and that works fine but I am having problems checking for the Null (Nothing) value with VB

Thanks

Shy
xx

  #10 (permalink)  
Old October 25th, 2006, 07:50 AM
Authorized User
Points: 176, Level: 3
Points: 176, Level: 3 Points: 176, Level: 3 Points: 176, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

CrossPagePostBack VB Version

Hi there!
Maybe my code is not perfect, but it finally works! Thank God!
I figured out that,in some cases we can't use PreviousPage Property, because, if we will go directly to the second page, PreviousPage Property will equal to Nothing.You simply can't use PreviousPage Property that contains Null. That's why you get Error.

I tried everything, Logical Operators, like C# code of this example, but nothing helped me to fix this NullReference error.
So I became with the idea about System.NullReferenceException.
Something I learned from the C# Basics about Exceptions.
This is really good way to catch some unexpected errors.

It took me a Night, to understand how to put this all together.
In the beginning, I should fist understand, how to build a VB version, because I don't familiar with VB Syntax.
(Some things that works in C# not allways works in VB.)

I took the original C# Idea of Handling Exceptions and wrote this in VB.

Finally this crappy SecondPage, began redirecting us to the FirstPage without Null-error. Thanks to the System.NullReferenceException :)

You can go directly to the Second page, and you'll be redirected.
You can post page to it self, and to the second page too.
Everything works fine.
Here's the code.

//--------------------------------------------------------------------

<script runat="server">


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

        Try
            If PreviousPage.IsCrossPagePostBack Then

                Label1.Text = "Hello " & PreviousPage.pp_TextBox1.Text & "<br />" & "Date Selected: " & PreviousPage.pp_Calendar1.SelectedDate.ToShortDate String()

            Else

                Response.Redirect("PageVb1.aspx")
            End If


        Catch ex As System.NullReferenceException
            Response.Redirect("PageVb1.aspx")


        End Try


    End Sub


As i figured out, we can use PreviousPageProperty,only if previousPage equals to some value,but not a Null-Nothing. When PreviousPage equals to Nothing, PreviousePageProperty becomes Unreachable(He don't know what to do with the null).It's more like, if it gets a Null from the previousPage,
PreviousPageProperty says: Oops! I don't know how to work with Nulls. So we need something that can identify Our null, and to do something with it. This is: System.NullReferenceException.
He say's I see the Null, I'm redirecting you, because you are a good guy :)


</script>

//----------------------------------------------------------------
You can check the Working example on my site:
http://aspspider.info/chadfunk/Cross...ageVB/1vb.aspx
 


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
Problem about "IsCrossPagePostBack" Property. condescendent ASP.NET 2.0 Professional 0 June 12th, 2007 09:26 PM
!!! ERROR In Wrox*PreviousPage.IsCrossPagePostBack dagad ASP.NET 2.0 Basics 1 March 22nd, 2007 09:57 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 09:44 PM.


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