Problem solve Get help with specific problems with your technologies, process and projects.

How can I get the value of TextBox1, which is in WebForm1, in WebForm2?

How can I get the value of TextBox1, which is in WebForm1 in WebForm2?
This depends on the case. If what you're doing is posting WebForm1 to WebForm2, you will get it from Request.Form. The more typical case, though, is to transfer processing on the server from one form to the other. Some people tend to think Response.Redirect is the better way to do this, but it's not. HTTP Redirection is a client-side mechanism, that's why you have it in Response in the first place! It causes the page to return to the client, where the browser performs the new request to the "redirected" new address. You lose all data from the previous form in this way.

The better way to pass data around forms (and to transfer processing from one page to another) is to use Server.Transfer and the HttpContext.Items property. Server.Transfer allows the current HttpContext (you can get it from Page.Context for example) to ?survive? the transfer. The HttpContext.Items property is an IDictionary (i.e. a Hashtable) where you can store arbitrary data to pass from one form to the next, prior to the transfer.

On the next form, you can simply get that data out of the context and use it:

string value = System.Web.HttpContext.Current.Items["incoming"] as string;

Dig Deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.