Server.Transfer in asp.net
Server.Transfer also exposes server side event just like as Response.Redirect. However there are some differences as well.
Now Again we have same problem. We wants to move from Page1.aspx to Page2.aspx on Button click.
Server.Transfer is having three overloading versions. I will discuss two of overloaded version here.
- Server.Transfer(string path);
- Server.Transfer(string path,bool preserveForm);
preserveForm ensures that the posted form values can be retrieved means if we post a page from Page 1 to Page 2 and we want to have Page 1 data values to be available on Page 2. All we have to do is send value of preserveForm=true. Well by default it is true so it is kind of optional.
Example:
- Server.Transfer("~/Page2.aspx");
- Server.Transfer("~/Page2.aspx",true);
So all we have to do is drag and drop a button and then we can generate event handler for it by double clicking on the button.
protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("~/Page2.aspx", true);
}
Difference Between Server.Transfer & Response.Redirect
No comments:
Post a Comment