tags:

views:

193

answers:

5

Hello,

I have an ASP.NET application I am working on. One of the requirements of this application is to not use query string parameters. The reason why is that the client feels it appears dirty and unprofessional. In addition, Session variables cannot be used either. In an effort to overcome these challenges, I decided to use hidden html elements with runat="server".

The challenge is, the page gets redirected to itself. The reason why is that the page represents a template in a list of 10 pages. If the user clicks "Next" the application needs to update the information for the second page. If the user clicks "Previous" the opposite needs to happen.

How do I read/set a hidden HTML field such that I can access the values I need on subsequent page requests?

Thank you!

A: 

From the little information I read here I am guessing that the wizard control could be right for you?

Other than that there is a Cross Page Postback you could use. It works without query strings or session.

Dun3
+1  A: 

You can access the value property of a hidden input just like a text input.

hiddenFieldPage.Value = "2"; // page 2!
if (hiddenFieldPage.Value == "2")
    // show page 2!

You might need to include System.Web.UI.HtmlControls. Alternatively I seem to recall an asp:hidden control which was basically a wrapper for the hidden input within the WebControls namespace.

Joel Potter
+1  A: 

ASP.NET uses LosFormatter class to serialize the view state. Essentially, you're doing a similar thing. Just store the data you want in an object and serialize it as a hidden form field. Use Request.Form["..."] to get the value back and deserialize it.

Mehrdad Afshari
I use the same approach. This works best for RIA with client side capability
David Robbins
+4  A: 

This is what the "ViewState" property is made for. It persists objects across roundtrips for you.

David
This is the best solution unless you need to access the values from JavaScript...
tekBlues
+1  A: 

Use the viewstate, is the best option for you situation:

// Storing a student in view state. Student stud = new Student("John", "Doe"); ViewState["CurrentStudent"] = stud;

// Retrieve a student from view state Student stud = (Student) ViewState["CurrentCustomer"];

Al you need to pay attention is that your classes must be serializable to be stored on the viewstate.

This is a nice tutorial to help you through.

holiveira