Showing posts with label response.redirect. Show all posts
Showing posts with label response.redirect. Show all posts

Monday, February 1, 2016

When we use Server.Transfer

Most of developer confused with "Server.Transfer" and "Response.Redirect", when we use this one and when we use that one. I think you all have to read the difference between "Server.Transfer" and "Response.Redirect".
  • The "Response.Redirect " makes the round trip and "Server.Transfer" does not.
I think we all know what round trip does, but here, I explain little bit of  the round trip

I explain it by taking an example

Suppose you have one button in your "aspx" page, when you click on that button your page is post back, the button click event will be fired, basically browser send request to the server and server processes that request and then send back to browser.

(Note:  The Web applications use HTTP to build up communication between the Web browser and the Web server. HTTP is disconnected in nature, which implies that the life cycle of a Web page is only a single roundtrip. Each time a Web server reacts to a page demand, it crisply makes the assets required to make the page, sends the page to the asking for customer and annihilates the page assets from the server. Between two page demands, Web server and the customers are separated with one another, and estimations of page variables and controls are not saved over the page demands.),

the server processes any code you attached to the button click event, creates a new page with the latest state of the page, and sends it back to the browser). That's one round trip.

When you can use Server.Transfer
  • When you do not want to round trip , because Server.Transfer direct communicate to the server or say "Server.Transfer" it directly communicate with the server to change the page hence it saves a roundtrip in the whole process and in case of "Responce.Redirect"  it first sends the request for the new page to the browser then browser sends the request for the new page to the webserver then after your page changes.
  • When you want to transfer page on same server . Suppose you write the code Server.Transfer("www.google.com");  It will raise error , in this case you can use "Responce.Redirect".
  • When you do not want to update the clients url history list or current url.