Please visit my new Web Site https://coderstechzone.com
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:
Hope now you can understand how to transfer or pass data between pages while using Server.Transfer.
5 comments:
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")
If you have no security issue than you can...
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
cool!
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!
Use Transfer("URL", false). Else, the form data is still sent to the destination page. No need to send it twice.
I WOULD BE DELIGHTED TO HEAR FROM YOU