3

When i write server.transfer("defaul2.aspx"); in url default2.aspx is not displaying instead of it is showing defaul.aspx page. when i write response.redirect("default2.aspx");

in url default2.aspx page is showing what is there any different.

jpaugh
  • 6,634
  • 4
  • 38
  • 90
Surya sasidhar
  • 29,607
  • 57
  • 139
  • 219
  • 2
    possible duplicate of [Server.Transfer Vs. Response.Redirect](http://stackoverflow.com/questions/224569/server-transfer-vs-response-redirect) – Fredou Feb 01 '11 at 12:40
  • It's not exact duplicate but answers this question as well. Hence I voted to close as well. – Robert Koritnik Feb 01 '11 at 12:43
  • You also misspelled "defaul2.aspx" (missing "t") in your Server.Transfer call. – SEFL Sep 16 '12 at 12:45

2 Answers2

10

That's because Server.Transfer() and Response.Redirect() don't work the same way.

Server.Transfer() doesn't end the current request, it only instructs ASP.NET to stop rendering the current page and start rendering the new page instead. The client is none the wiser, from its point of view the server is still responding to the initial request, so the URL displayed in the address bar does not change.

Response.Redirect() ends the current request and sends a 302 response code to the client. The client then issues another HTTP request to the redirected URL and processes the response. Since the client knows that the URL has changed, it displays the redirected URL in its address bar.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
2

Response.Redirect method:
it helps in navigating to another page from code. This is like clicking a hyperlink.To navigate from one page to another using button click or linkbutton control or from server side code use Response Object's Redirect method. using Response.rediect() method you can not get information from source page on target page. its source code is like VB.Net Code

Private Sub Button1_Click(ByVal Sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
    'Display target page.
    Response.Redirect("Target.aspx")
End Sub

C# Code

private void Button1_Click(Object sender, System.EventArgs e)
{
        //Display Target Page.
        Response.Redirect("Target.aspx");
}

Using Server.Execute Method
use Server.Execute Method to process a Target web form without leaving the Source page. This technique let you embed the result from a target page to a region on Source page. Like Server.Transfer, It also required EnableViewStateMac attribute to page directive set to false. Suppose I have to pages one is Calculate.aspx having two textboxes and a button control. On button Click event. I performed Server.Execute to Result.aspx another aspx page. Source Code:

 protected void btn_Click(object sender, EventArgs e)
{
    Server.Execute("Result.aspx");
}

write below code in Result.aspx pageload event.

protected void Page_Load(object sender, EventArgs e)
{
    NameValueCollection colform = new NameValueCollection();
    colform = Request.Form;
    Response.Write("<h2>Additon Result:</h2>" + (Convert.ToInt32(colform["TextBox1"]) + Convert.ToInt32(colform["TextBox2"])));
}
davidsleeps
  • 9,393
  • 11
  • 59
  • 73
SHEKHAR SHETE
  • 5,964
  • 15
  • 85
  • 143