How to transfer information between pages in ASP.NET using a query string in C#

Software developer can use this approach for information that don’t need to be hidden or made tamper-prof. Unlike view state information passed through the query string is clearly visible and unencrypted. The query string is the portion of the URL after the question mark in the following example:

C# in Depth, 3rd EditionManaged Windows VPS Hosting

Software developer can store information in the query string himself using special Response.Redirect() statement such as the one shown here:

// Go to a mypage.aspx. Submit a single query string argument named numberID and set it to 100.

The developer can send multiple parameters as long as they are separated with an ampersand (&)

// Go to a mypage.aspx. Submit two query string arguments numberID (100) and color (red).

Software developer has to include the code above in the code for event which redirects end user to another page.

The receiving page can retrieve the values from the QueryString dictionary collection exposed by the built-in Request object. Software developer can include the next code in the Page_Load event:

string ID = Request.QueryString[“numberID”];

Note: This information is always retrieved as a string, which can then be converted to another simple data type. Values in the QueryString collection are indexed by the variable name.