tags:

views:

191

answers:

3

Hi,

I have a wizard style interface where I need to collect data from users. I've been asked by my managers that the information is to be collected in a step by step type process.

I've decided to have a page.aspx with each step of the process as a separate user control. step1.ascx step2.ascx etc...

The way it works now, is that when the initial GET request comes in, I render the entire page (which sits inside of a master page) and step1.ascx. When then next POST request comes in for step 2 (using query string step=2), I render only step2.ascx to the browser by overriding the Render(HtmlTextWriter) method and use jQuery html() method to replace the contents of a div.

The problem with this whole approach, besides being hacky (in my opinion) is that it's impossible to update viewstate as this is usually handled server side.

My workaround is to store the contents of step1.ascx into temporary session storage so if the user decides to click the Back button to go back one step, I can spit out the values that were stored for it previously.

I feel I'm putting on my techy hat on here in wanting to try the latest Javascript craze as jQuery with .NET has taken a lot of hack like approaches and reverse engineering to get right. Would it be easier to simply use an updatepanel and be done with it or is there a site with a comprehensive resource of using jQuery to do everything in ASP.NET?

Thanks for taking the time to read this.

+7  A: 

Another approach, that might be easier to work with, is to load the entire form with the initial GET request, and then hide all sections except the first one. You then use jQuery to hide and show different parts of the form, and when the final section is shown the entire form is posted in one POST to the server. That way you can handle the input on the server just as if the data entry was done in one step by the user, and still get the step-by-step expreience on the client side.

Tomas Lycken
I use this technique sometimes.
Justice
As a plus, you get compatibility with browsers with javascript turned off
Eduardo Molteni
A: 

Did you look into using the ASP.NET Wizard control? It's a bit of a challenge to customize the UI, but otherwise it's worked well for me in similar scenarios.

Jamie Ide
Does it work with jquery and viewstate?
Sir Psycho
Yes to ViewState, I don't know to JQuery. The user experience of navigating back and forth among wizard screens is going to be pretty similar for both ASP.NET postbacks and JQuery, I would think.
Jamie Ide
As I understood the question, however, a requirement was to do this with jQuery and only partial postbacks, if any. Sure, a Wizard control in an UpdatePanel could probably do the job, but with a _lot_ of overhead...
Tomas Lycken
Update panels provide partial rendering, not partial postbacks so Im trying to avoid this.
Sir Psycho
Update Panels provide partial postback as well - make sure you use UpdateMode=Conditional and do not have XML conformance set to legacy in your web.config
Rob Allen
+1  A: 

You could just place all your user controls one after another and turn on the visibility of the current step's control and turn on other controls when appropriate . No need to mess with overriding Render(). This way the user controls' viewstate will be managed by the server. and you can focus on any step validation logic.

Using an UpdatePanel to contain the steps would give the ajax experience and still be able to provide validation on each step. If you are OK with validating multiple steps at once, Tomas Lycken's suggestion (hide/show with JQuery), would give a fast step by step experience.

HectorMac