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.

3 comments:

shafiq said...

this is a good one...and it solved my problem....one thing i am very confused about is,why we can not send value in query string like
Response.Redirect("A.aspx?Id=11&Pass=22")

Shawpnendu said...

If you have no security issue than you can...

ocha's blog said...

Cool..
Im trying to send value to generic Handler page, like:
Server.Transfer("Handler1.ashx");
But i got error message :
Error executing child request for Handler1.ashx.

Could u help me please to solve this problem??

Thank You before

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