Fabiano
Fabiano

Reputation: 5194

redirect to current page in ASP.Net

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.

What other/better methods can I use to achieve the same?

Upvotes: 54

Views: 117062

Answers (2)

epitka
epitka

Reputation: 17627

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

Upvotes: 124

kervin
kervin

Reputation: 11858

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.

Upvotes: 18

Related Questions