Friday, December 3, 2010

Using Server.Transfer how to pass values from source page to destination page

It's not possible to pass value using query string from source page to destination page when using Server.Transfer. To pass data or value from source page to destination page while using Server.Transfer you can use HttpContext object. To do that add two aspx pages in your project & give name source.aspx & destination.aspx. In source.aspx page place a LinkButton. And under the LinkButton Click event write the below code:

To learn Difference Between Response.Redirect vs Server.Transfer Click Here.









protected void Linkbutton1_Click(object sender, EventArgs e)

{

HttpContext CurrContext = HttpContext.Current;

CurrContext.Items.Add("Name", "Shawpnendu Bikash Maloroy");

CurrContext.Items.Add("Address", "Dhaka, Bangladesh");

Server.Transfer("Destination.aspx");

}

In Destination.aspx Page under Load event write the below code:
protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

HttpContext CurrContext = HttpContext.Current;

Response.Write(CurrContext.Items["Name"].ToString()+" ");

Response.Write(CurrContext.Items["Address"].ToString());

}

}

Now run the source.aspx page & click on the LinkButton. You will get below output:

Server.transfer

Hope now you can understand how to transfer or pass data between pages while using Server.Transfer.

0 comments:

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash