views:

384

answers:

3

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 );
+2  A: 

Do a cross-page postback instead?

MSDN: Cross-Page Posting in ASP.NET

Jon Seigel
Thanks Jon, this was the right direction, but for some reason, the PreviousPage.FindControl specified in the documentation wasn't working for me, the controls were marked public as well.
Jason w
+1  A: 

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.

Tim Santeford
thanks for the effort, but this still isn't solving the issue.
Jason w
+1  A: 

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
        }
    }
}
Chris
Thank you, i had tried the cross page postback before, but was trying to use PreviousPage.FindControl and it wasn't working, but if i expose the values i need as properties it works like a champ.
Jason w