Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6911303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:56:07+00:00 2026-05-27T08:56:07+00:00

There are two scenarios for an ASP.net webforms page which I would like to

  • 0

There are two scenarios for an ASP.net webforms page which I would like to differentiate between: “Normal postback” and when a page is created because the next page has called PreviousPage.

  • A normal posback occured for page 1
    • IsPostback is true
    • IsCrossPagePostBack is false

and

  • There was a Server.Transfer("page2.aspx") to page 2, and page 2 uses PreviousPage so page 1 is created virtually. For page 1:
    • IsPostback is true
    • IsCrossPagePostBack is false

You can see that IsPostBack and IsCrossPagePostBack do not help because they are the same in both cases.

The reason why I am asking this:

I have page 1 which sends data to page 2 via cross-page postback (PostBackUrl="page2.aspx" set in page 1). For all users who have javascript enabled, this works fine.

But I wanted also a fallback for the users who have javascript disabled. For them, a click on the submit button on page 1 does not lead to page 2 but to a postback to page 1. Page 1 could now detect this and do a Server.Transfer("page2.aspx") to page 2. The problem is: When page 2 uses PreviousPage then page 1 is created again and would do a Server.Transfer() again and again and again …

My workaround for this is to do the Server.Transfer not in the Page_Load event but only in the Page_PreRender event because this event does only occur when it is a normal postback and not when the page is created as PreviousPage.
This workaround works but it is very dirty. If I could differentiate between the two scenarios already in the Page_Load event, it would be much better.

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:56:08+00:00Added an answer on May 27, 2026 at 8:56 am

    When you do the HttpServerUtility.Transfer from Page 1 to Page 2, the HttpContext is then shared between Page 1 and Page 2. So normally, one request means one request handler (usually a page) and one request context. But in this case there’s two handlers and one (shared) context. You can use the context to share information about the request between the two handlers.

    So one solution may be that Page 1 puts all the data that page 2 needs in the HttpContext.Items. Then Page 2 first checks for this data. If present, Page 2 knows that control was transferred by way of Server.Transfer and that it should not call on Page 1 through PreviousPage. Instead it should now get its data from the context.

    Page1.aspx

    protected void Page_Load(object sender, EventArgs e)
    {
        if(IsPostBack && HttpContext.Items.Contains("CrossPagePostBack") == false)
        {
           // Cross page postback did not succeed (JavaScript disabled)
           string name = NameTextBox.Text;
           HttpContext.Items.Add("Name", name);
    
           HttpContext.Items.Add("Transfer", true);
           Server.Transfer("Page2.aspx");
        }
    }
    

    Page2.aspx

    protected void Page_Load()
    {
        if(IsPostBack)
        {
            string name;
            if(CrossPagePostBack)
            {
                // Cross page postback succeeded (JavaScript was enabled)
                HttpContext.Items.Add("CrossPagePostBack", true);
                name = PreviousPage.NameTextBox.Text;
            }
            else if (HttpContext.Items.Contains("Transfer"))
            {
                // We got transferred to from Page1.aspx
                name = (string)HttpContext.Items["Name"];
            }
    
            // Do something with Page 1's form value(s)
        }
    }
    

    Or you can turn this around and let Page 2 add a mark (“Page 2 was here”) to the HttpContext.Items, and then Page 1 checks that mark. If it’s present it doesn’t need to transfer again (break the loop). I’m not 100% sure if a call to PreviousPage also results in a shared request context.

    Page1.aspx

    protected void Page_Load(object sender, EventArgs e)
    {
        if(IsPostBack && HttpContext.Items.Contains("CrossPagePostBack") == false)
        {
            // Cross page postback did not succeed (JavaScript disabled)
           if(HttpContext.Items.Contains("Transfer"))
           {
               // We did not yet transfer to Page 2
               HttpContext.Items.Add("Transfer", true);
               Server.Transfer("Page2.aspx");
           }
        }
    }
    

    Page2.aspx

    protected void Page_Load()
    {
        if(IsPostBack) 
        {        
            if(CrossPagePostback)
            {
                // Cross page postback succeeded (JavaScript enabled)
                HttpContext.Items.Add("CrossPagePostBack", true);
            }
    
            string name = PreviousPage.NameTextBox.Text;
    
            // Do something with Page 1's form value(s)
        }
    }
    

    The second method is simpler in implementation, especially if the form on Page 1 is complex. You’d have only one place where you read Page 1’s form, and you only add a simple boolean to the HttpContext.Items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two scenarios I need to clarify: An executable compiled with .NET 3.5
It seems to me that there are two scenarios in which to use JOINs:
Using ASP.NET Entity Framework, how can I change the Foreign Key association between two
Is there a performance and/or memory usage difference between these two scenarios? scenario 1:
I have two distinct scenarios. One, where there is a many to many case,
I was wondering about the performance difference between these two scenarios and what could
I was wondering which of these two scenario's works best for swapping between 2
i'd like to recieve comments on the way i'm trying to build an asp.net
Scenario: We have a server where there are multiple ASP.NET websites hosted on it.
(Note: these two questions are similar, but more specific to ASP.Net) Consider a typical

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.