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?

- 82,532
- 99
- 305
- 486
-
Are you looking to do this in javascript client-side? – James King Aug 16 '10 at 17:09
-
No i am not. Anything that works. – Abe Miessler Aug 16 '10 at 17:18
-
It is not possible to do a postback from codebehind. this is almost a duplicate question of this: http://stackoverflow.com/questions/60650/asp-net-is-it-possible-to-trigger-a-postback-from-server-code – Joakim Aug 16 '10 at 18:20
2 Answers
Try Response.Redirect
UPDATE:
You can't do a proper postback from codebehind to my knowledge I'm afraid

- 82,532
- 99
- 305
- 486

- 2,217
- 15
- 20
-
That doesn't post any data from my current page to my target page does it? – Abe Miessler Aug 16 '10 at 17:07
-
-
Storing in session is not an option. Neither are parameters. Are you guys telling me it can't be done? – Abe Miessler Aug 16 '10 at 17:17
-
You can't do a proper postback from codebehind to my knowledge I'm afraid – Joakim Aug 16 '10 at 17:25
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.

- 9,470
- 4
- 39
- 66
-
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 Aug 16 '10 at 18:10
-
@Abe Miessler - I added another idea to my answer that I think is closer to what your question is asking. – DaveB Aug 16 '10 at 18:48