Server.Transfer
Passing data from onepage to another we use Server.Transfer and other method. Server.Transfer isprovide more efficient result as comparison to other.
“The Page representing the page thattransferred control to the current page.”
How use the Server.Transfer
Forexample
Step 1:
We add the onepage as Default1.aspx and add one TextBox and Button and write this code onbutton click
protected voidButton1_Click(object sender, EventArgs e)
{
Server.Transfer("Default2.aspx");
}
Step2:
We access the textbox control data on this current page,we write the this code on page load
protected voidPage_Load(object sender, EventArgs e)
{
TextBox txt = (TextBox)Page.PreviousPage.FindControl("TextBox1");
Label1.Text =txt.Text;
}
So, we access the previous page data very fast as comparisonto response.redirect. so it one important method “to pass the data from one page to another”.Server.Transferacts as an efficient replacement for the Response.Redirect method.Response.Redirect specifies to the browser to request a different page. Becausea redirect forces a new page request, the browser makes two requests to the Webserver, so the Web server handles an extra request.
Donald Stanley
18-Oct-2022Thanks for asking this I was also looking for the same
Sunil Singh
14-Jun-2017It was really helpful to read this post.