ASP.NET – Server.Transfer v/s Server.Execute
October 14, 2007 by Prashant Pandey
Introduction
Difference between Server.Transfer and Server.Execute. |
Server.Transfer v/s Server.Execute |
- Both Server.Transfer and Server.Execute were introduced in Classic ASP 3.0 (and still work in ASP.NET).
- When Server.Execute is used, a URL is passed to it as a parameter, and the control moves to this new page. Execution of code happens on the new page. Once code execution gets over, the control returns to the initial page, just after where it was called. However, in the case of Server.Transfer, it works very much the same, the difference being the execution stops at the new page itself (means the control isn’t returned to the calling page).
- In both the cases, the URL in the browser remains the first page URL (doesn’t refresh to the new page URL) as the browser isn’t requested to do so.
These are common differences, if anyone knows any other difference other than these then please give your comments.
Thank you,
Reference : Prashant Pandey (TechAhead) |
|
*******
|
 |
Reference from and many thanks to following websites and articles:
DotNEtUncle |
Posted in ASP.NET | 16 Comments
Leave a Reply
The difference between the two methods is that executing a page will insert the second page’s content into the first page, whereas transferring redirects to the second page, while still referencing the first page in the browser’s address ba
Hello! Good site! I’m From Khazahstan! I’m doing well!
Thank you!
very interesting, but I don’t agree with you
Idetrorce
Hi Idetrorce,
Can you please tell me the reason why ur not agree with me? It will help me to correct the mistake if i have done in this article???
Thanks,
prashantvictory is right.
hi here arun u
I want to know can we pass query string values in Server.Transfer, Server.Execute
Hi Ashish,
Sorry for late reply, but i was just preparing a sample application for you.
1. Server.Transfer – You can use the quer string values. Just try with any pages like Server.Transfer(”urPageName.aspx?login=prashant”) it will work.
2.Server.Execute – Its answer is also yes, you can use query string values with Server.Excute tooo. For demonstrate this i have created a sample application please have a look of this by downloading the example zip file from following url:
http://cid-9e5547502c371bbc.skydrive.live.com/self.aspx/Public/techAhead/serverExecute-example/serverExecute.zip
Thanks.
hi,
i got the good idea to read it.
plz continue it ,
thanking you
hi frds,
i got gud answer from all of u, thanks
Great Job guys!!! Good work Prashant…
This is good.
The only drawback is that, as Kiran mentioned, the browser’s address bar shows the old page’s URL instead of the new one, which can be confusing for the user not to mention the developer.
Good one Prashant and Kiran
Hi,
I would like to execute the contents from the other page. After that i want to coming back to my original page. But when i am using the server.execute, it is inserting the content from the second page. Someone please let me know how to avoid this?( I don’t want to insert the content from the second page).
Hi All,
Quick points:
1. You CANNOT pass querystring to the receiving page in Server.Transfer method
that is the following code does NOT work from testServerTransfer.aspx
Server.Transfer(”testServerTransfer2.asp?q1=test&q2=me”)
[Checked with IIS 5.5 on Win XP with .NET Framework 2.0]
However, let us assume that testServerTransfer.aspx had already received a querystring (or a
form via GET HTTP header), then the same can be passed on to testServerTransfer2.aspx
2. The reason browser displays the old URL after Server.Transfer is that ASP engine puts the contents of testServerTransfer2.aspx into the response rather than start a new request/response thread.
3. MOST IMPORTANT: You can use Server.Transfer only if you are transferring within the same virtual directory.
Example: Server.Transfer(”/virt2/testServerTransfer2.aspx”)
results in an exception when called from /virt1/testServerTransfer.aspx
–Regards
Sudhanshu Mishra
Hello, I am asking about does the excuted page working in the same thread with the caller
Nice article
Thanks for this
http://cid-9e5547502c371bbc.skydrive.live.com/self.aspx/Public/techAhead/serverExecute-example/serverExecute.zip