There are a couple options for doing this, and they will depend on the storage location as well as its "longevity." First, you can use the "old" cookies mechanism. That is, on one page you store cookies, then perform a Response.Redirect, and pick those values back in the next. Second, you can use the Session to store those values. This consumes server resources, however, that last for the whole user session unless you explicitly clear them. Third, my favorite one, is to store those values in the HttpContext.Current.Items collection, and perform a Server.Transfer to the next page. HttpContext.Items stores what I call Transient State, which only lives during a single request, therefore, doesn't consume server resources after the request has been served. This is the store used by built-in features such as Forms Authentication, so you can be pretty confident that it's not a "hack" but a powerful feature. Beware, however, that you can't do a Response.Redirect, because it involves a return to the client, and a client-side redirect, which makes for a completely different Request, therefore, the context is lost.
Dig Deeper on C# programming language
Related Q&A from Daniel Cazzulino
Here Daniel Cazzulino explains how to load a DSL (domain specific language) domain model instance file programmatically. This requires the .NET type ... Continue Reading
Here we offer a glimpse at 12 of .NET development expert Danny Cazzulino's top ASP.NET questions and answers. Continue Reading
C# developers should NOT be modifying InitializeComponent method in the code-behind (or any of the variable definitions) by hand. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.