jasonmw
jasonmw

Reputation: 1138

IE and Firefox different postback Behavior after Server.Transfer

I have 2 aspx pages, in a postback event from page 1, i add data to the current context, then do a server.transfer to page 2. this all works as expected, however due to the server.transfer, the address bar still shows the url for page 1.

the weirdness comes when i click a button on page 2.

in IE (7 or 8) when i click a button on page 2, the page posts to page 2 as expected.

in Firefox when i click a button on page 2, the page posts to page 1.

Has anyone else experienced this? Am i doing something wrong? Is there a workaround?

this is essentially the code in page 1

Context.Items["x"] = x.Checked;
Context.Items["y"] = y.Checked;
Context.Items["z"] = z.Checked;
Server.Transfer( "page2.aspx", false );

Upvotes: 1

Views: 1535

Answers (3)

Chris
Chris

Reputation: 2055

If you're not using PreviousPage, you could use Response.Redirect("~/Page2.aspx"); instead. This will inform the user's browser of the page change.

Alternatively, if you are using PreviousPage use a cross-page post back by setting the PostBackUrl attribute on the desired Button. This will allow your Server.Transfer logic to be properly handled. To get access to the CheckBox's value you will need to make public properties on Page1 that will be accessible through the PreviousPage.

So Page1 will contain these properties in the code behind:

public bool xChecked { get x.Checked; }
public bool yChecked { get y.Checked; }
public bool zChecked { get z.Checked; }

Page2 will use PreviousPage:

protected void Page_Load()
{
    if(PreviousPage != null && PreviousPage is Page1)
    {
        if(((Page1)PreviousPage).xChecked)
        {
            //use xChecked like this
        }
    }
}

Upvotes: 1

Tim Santeford
Tim Santeford

Reputation: 28131

You could try setting the form.action to the specific page you want to post to.

page 2's Form Load Event:

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Me.Form.Action = "page2.aspx"
End Sub

This should guaranty posting to the correct page.

Upvotes: 1

Jon Seigel
Jon Seigel

Reputation: 12401

Do a cross-page postback instead?

MSDN: Cross-Page Posting in ASP.NET

Upvotes: 2

Related Questions