开发者

Post data to different ASP.NET WebForm

开发者 https://www.devze.com 2023-01-07 10:21 出处:网络
In my ASP.NET WebForms application, I have a WebForm that contains an UpdatePanel and multiple views used for a wizard like interface.

In my ASP.NET WebForms application, I have a WebForm that contains an UpdatePanel and multiple views used for a wizard like interface.

开发者_如何学运维

At the end of the wizard, the user has an option of moving to another page by clicking a button. This new web page needs about 5 values from controls in the previous page.

What is the simplest way to do this? (Edit: ONLY using an HTTP POST with data - this is a requirement as I would use database/session otherwise)

I tried using cross-page posting with no luck, possibly because of my update panel and multiple views?

I tried using Server.Transfer, but this also breaks because of the update panel.

Important:

  1. Data has to be sent via HTTP POST - The data can't be stored anywhere
  2. The scenario can't be changed. I can't put everything on the same page


The simplest way to do this is by putting those values in the session object.


You could make a class that describes the data that you need to display on the redirected page. Instatiate a new instance of that at the time the user is filling out the wizard data, populate the new classes' object with the information you need, then add it to the session in the button_Click event before page redirection. On the page you are redirected to, grab the Session object, put it into a variable and extract the data you need.


I recommend you combine all the relevant pages into one; hiding panels that are not in play. ASP.NET will maintain the values of all the controls for you from post to post. The Viewstate was designed for sceneries like you describe. To keep to Viewstate size to a minimum, make sure you fill lookup values for drop-down controls in their "Init" methods.

You don't want to use the session state. The last thing you want is for the users to loose their data from previous pages because they took too long to answer.


If they're moving to another page in the solution, you have a few options.

  1. ViewState - The ViewState is sent with the page delivery. It resides in the HTML, but is encrypted so no one can see the information. Depending on the size of the information, your page size could get rather large.
  2. Session - This puts the information client-side via cookies.
  3. Query String - Using the URI. This should only be used if it's non-sensitive information and if you don't want a user to be able to link back to the same action again.
0

精彩评论

暂无评论...
验证码 换一张
取 消