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.










0 comments:
I WOULD BE DELIGHTED TO HEAR FROM YOU