CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Pass Value to Destination Page When Using Server.Transfer in Asp.Net
Submitted By Satheesh Babu B
On 8/25/2009 7:58:27 AM
Tags: ASP.Net,CodeDigest  

Pass Value to Destination Page When Using Server.Transfer in Asp.Net

 

It will not be possible to pass value as query string to the destination page when using Server.Transfer.

 

To pass value from source page to destination page when using Server.Transfer we can use the Item collection in HttpContext object. The below code does that,

Source Page
protected void Button1_Click(object sender, EventArgs e)

    {

         HttpContext CurrentCon = HttpContext.Current;

         CurrentCon.Items.Add("CatID", "Computer");

         Server.Transfer("Destination.aspx");

    }


Destination Page

protected void Page_Load(object sender, EventArgs e)

    {

        HttpContext CurrentCon = HttpContext.Current;

        string CatID = CurrentCon.Items["CatID"].ToString();

 

        Response.Write(CatID);

    }

 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..