views:

79

answers:

2

Hi

How can I perform a redirect with Server.Transfer() to the same page that is currently shown. I want to have A cleared form after submit.

Thanks

+2  A: 

Why Server.Transfer? Response.Redirect(Request.RawUrl) would get you what you need

epitka
-1 This is a waste of a round trip between the server and the browser
Daniel Dyson
I think that Server.Transfer is the better option. But your solution does the trick too. I'm using now Server.Transfer(Request.Path);
Fabiano
@Daniel: It's not a wasted round trip. Quite often you don't want the last request in your user's browsers page stack to be the result of an HTTP POST. Users will often refresh and repeat that action. Transfer doesn't fix that, but Redirect does.
kervin
@Daniel: Exactly, ever heard of Post-Redirect-Get pattern? If not here is some info for you: http://en.wikipedia.org/wiki/Post/Redirect/Get
epitka
Fair comments. I am unable to remove my down-vote unless the post is edited, apparently.
Daniel Dyson
+1  A: 

http://en.wikipedia.org/wiki/Post/Redirect/Get

The most common way to implement this pattern in ASP.Net is to use Response.Redirect(Request.RawUrl)

Consider the differences between Redirect and Transfer. Transfer really isn't telling the browser to forward to a clear form, it's simply returning a cleared form. That may or may not be what you want.

Response.Redirect() does not a waste round trip. If you post to a script that clears the form by Server.Transfer() and reload you will be asked to repost by most browsers since the last action was a HTTP POST. This may cause your users to unintentionally repeat some action, eg. place a second order which will have to be voided later.

kervin