开发者

IE and Firefox different postback Behavior after Server.Transfer

开发者 https://www.devze.com 2022-12-08 08:50 出处:网络
I have 2 aspx pages, in a postback event from page 1, i add data to the current context, then do a server.trans开发者_开发问答fer to page 2.this all works as expected, however due to the server.transf

I have 2 aspx pages, in a postback event from page 1, i add data to the current context, then do a server.trans开发者_开发问答fer 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 );


Do a cross-page postback instead?

MSDN: Cross-Page Posting in ASP.NET


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
        }
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消