ASP.NET Server.Transfer & Server.Execute
ASP.NET Server.Transfer & Server.Execute
1. Server.execute : go to other site , do processing and return.
Will show the Default2.aspx . Url not changed. We have both pages webcontrol. URL will changed after the postback and Response stream & Web control of previous page will lost.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("eid") = "009383"
Session.Timeout = 1 'make session for 1 minute
'Server.Transfer("Default2.aspx") 'page accessed without changing url
Server.Execute("Default2.aspx")
End Sub
2. Server.Transfer will show the Default2.aspx page without changing url will access here the response stream of Default.aspx page.& Web Control of Default.aspx page will lost. No Roundtrip. URL will changed after the postback and Response stream ( Web controls already) of previous page will lost.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("eid") = "009383"
Session.Timeout = 1 'make session for 1 minute
Server.Transfer("Default2.aspx")
End Sub
Here is the Default2.aspx Page for both methods shown above
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("Page2")
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write(Session("eid") & "v")
' Session.Clear() ''clear the value part of session
End Sub
3. Response.Redirect("Default.aspx") will completley nevigate to other page. Kill response stream as well as web controls of calling page.
- Vinod Kotiya
Comments