Friday, December 3, 2010

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

Please visit my new Web Site

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");



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()+" ");




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


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


shafiq said...

this is a good one...and it solved my thing i am very confused about is,why we can not send value in query string like

Shawpnendu said...

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

ocha's blog said...

Im trying to send value to generic Handler page, like:
But i got error message :
Error executing child request for Handler1.ashx.

Could u help me please to solve this problem??

Thank You before

Alex said...


i had a form which i made a server.tranfer() to with query string parameters, and after it made postback to itself, the query string was showing up. i spent half a day figuring out how can i hide it, and that's the way - using httpocntext. thank you!

Mr. Logic said...

Use Transfer("URL", false). Else, the form data is still sent to the destination page. No need to send it twice.

Want to say something?

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • 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