ASP.NET cross-page postbacks: PreviousPage and PreviousPage.IsCrossPagePostBack

Posted by: Jotekes Blog, on 12 Jul 2007 | View original | Bookmarked: 0 time(s)

There has been some confusion on Forums related to PreviousPage property, especially whether one should check only PreviousPage property for null reference and why there's IsCrossPagePostBack property too.

It is so that basically PreviousPage property on target page is non-null in both cases following

  • Page is loaded by being target page on cross-page postback
  • Page is loaded by being target page on Server.Transfer

However, IsCrossPagePostBack property is true only in "real" cross-page postback while with Server.Transfer it is false.

So this adds to the "soup" that if you intend to use your Page also as normal page - that is, it can be used without cross-page postback - you need to check PreviousPage property for null reference. But in practise, checking only PreviousPage property for null reference is quite enough for the cases you deal with cross-page postbacks. You usually want to access the source page's controls in a way or another and therefore it is quite the same was the Page loaded with cross-page postback or Server.Transfer.

So some sort of pseudocode to distinguish these scenarios:

[VB.NET]

    'This logic on target page, note checking via PreviousPage property
        If Not PreviousPage Is Nothing Then

            If PreviousPage.IsCrossPagePostBack Then
                'Standard cross-page postback
            Else
                'Server.Transfer
            End If

        Else
            'Standard use without cross-page postback
        End If

[C#]
 //This logic on target page, note checking via PreviousPage property
 if (PreviousPage != null)
            {
                if (PreviousPage.IsCrossPagePostBack)
                {
                    //Standard cross-page postback
                }
                else
                {
                       //Server.Transfer
                }
            }
            else
            {
                //Standard use without cross-page postback
            }

And as usual, it's also quite well in the docs: http://msdn2.microsoft.com/en-us/library/ms178141.aspx

Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 2718 | Hits: 89

Similar Posts

  • SQL SERVER PAGELATCH_DT, PAGELATCH_EX, PAGELATCH_KP, PAGELATCH_SH, PAGELATCH_UP Wait Type Day 12 of 28 more
  • SQL SERVER PAGEIOLATCH_DT, PAGEIOLATCH_EX, PAGEIOLATCH_KP, PAGEIOLATCH_SH, PAGEIOLATCH_UP Wait Type Day 9 of 28 more
  • Reporting Release History : Q2 2009 SP1 (version 3.1.9.807) more
  • Silverlight 3 Navigation: Dynamically Loaded Pages Now MEF Powered! more
  • WebResource access in ASP.NET MVC more
  • Adding Persistence to the .NETOOP Edit in Place control. more
  • ViewModel with MVC/Navigation in Silverlight more
  • Put Your Pages and Views on Lockdown more
  • Displaying XPS Documents in Silverlight more
  • ASP.NET MVC Plan 9 Sample more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD