Matt R
Matt R

Reputation: 2617

When would I use Server.Transfer over PostBackURL?

Or vice versa.

Update:
Hmm, let's assume I have a shopping cart app, the user clicks on the Checkout button. The next thing I want to do is send the user to a Invoice.aspx page (or similar). When the user hits checkout, I could Button.PostBackURL = "Invoice.aspx"

or I could do

Server.Transfer("Invoice.aspx")

(I also changed the title since the method is called Transfer and not TransferURL)

Upvotes: 3

Views: 3554

Answers (3)

Gulzar Nazim
Gulzar Nazim

Reputation: 52178

Server.Transfer is done entirely from the server. Postback is initiated from the client for posting form contents and postback url identifies the page to post to.

Maybe you meant to compare with Response.Redirect, which forces the client to submit a new request for a new url.

Upvotes: 1

Dave Carroll
Dave Carroll

Reputation: 86

  • Server.TransferURL will not result in a roundtrip of HTTP request/response. The address bar will not update, as far as the browser knows it has received only one document. Server.Transfer also retains execution context, so the script "keeps going" as opposed to "starts anew".
  • PostbackURL ensures an HTTP request, resulting in a possibly different URL and of course incurring network latency costs.

Usually when you are attempting to "decide between the two" it means you are better off using PostbackURL.

Feel free to expand your question with specifics and we can look at your precise needs.

Upvotes: 6

Thunder3
Thunder3

Reputation: 1120

Here is a good breakdown between the two:

Server.Transfer vs Response.Redirect

Upvotes: 3

Related Questions