Thursday 5 November 2015

Response.Redirect in Asp.Net

Response.Redirect is very similar to HyperLink control. But the basic difference is HyperLink does not expose any server side event. For example if we want a button and when we click on button, we want to go to Page2.aspx .

protected void Button1_Click(object sender, EventArgs e)
{
        Response.Redirect("~/Page2.aspx");
}

Response.Redirect change the URL in address page and it can be used to navigate pages/website on the same web server or on a different web server.

It has two overloading versions:

  1. Response.Redirect(string Url);
  2. Response.Redirect(string Url,bool endResponse);
Response.Redirect(URL,false) :- Client is redirected to a new page and the current page on the server will keep processing ahead.

Response.Redirect(URL,true) :- Client is redirected to a new page but the processing of the current page is aborted. 

No comments:

Post a Comment