blog

Home / DeveloperSection / Blogs / Server.Transfer: how use it

Server.Transfer: how use it

Amit Singh 4519 31-Oct-2010
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.”
 
When you use the Transfermethod or use cross-page posting totransfer processing from one ASP.NET page to another, the originating pagecontains request information that might be required for the destination page.You can use the PreviousPageproperty to access that information.

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.

 


Updated 18-Sep-2014

Leave Comment

Comments

Liked By