views:

43

answers:

2

I want to do something similar to what happens when you click an asp.net button that has a PostBackURL set. I've tried Server.Transfer but the URL doesn't change (which is something I want). Is there a better way to do this, or alternatively is there a way to make Server.Transfer display the correct URL?

+1  A: 

Try Response.Redirect

UPDATE:

You can't do a proper postback from codebehind to my knowledge I'm afraid

Joakim
That doesn't post any data from my current page to my target page does it?
Abe Miessler
No it won't, you'll have to store that in ex. session
Joakim
Or pass as parameters.
David Robbins
Storing in session is not an option. Neither are parameters. Are you guys telling me it can't be done?
Abe Miessler
You can't do a proper postback from codebehind to my knowledge I'm afraid
Joakim
A: 

See:

Cross-Page Posting in ASP.NET Web Pages

How to: Post ASP.NET Web Pages to a Different Page

asp:Button 
  ID="Button1" 
  PostBackUrl="~/TargetPage.aspx"
  runat="server"
  Text="Submit" />

Edit: You could also construct a HTTP POST in the codebehind and send it to the target page then write the response out to the browser. This won't change the URL in the brower's address bar to the actual page that the data was POSTed to. What you can do depends on what control you have. Is the page that is POSTed to under your control? Do it contain any text/data that is specific to what is POSTed to it? You could do the POST and then redirect/transfer to the target page but that may or may not display the result of the POST correctly.

How to use HttpWebRequest to send POST request to another web server may be of some help if you decide to go this way.

DaveB
I've seen those two pages already and neither provide me with information that answers my question. I am also aware of the PostBackUrl attribute. As my question states I am trying to reproduce (from code behind) the behavior of clicking a button with that attribute set. Can this be done?
Abe Miessler
@Abe Miessler - I added another idea to my answer that I think is closer to what your question is asking.
DaveB