views:

646

answers:

1

I've got a wizard control that databound controls on each step. I can't databind them all at once because they are dependent on the previous step. So, essentially what I've got at each step is a save to the database of the previous step, and an initialization of the current step.

Are there any recommendations as to how best to organize my code? It works, but it's not very readable, and extremely brittle.

Please help! :)

EDIT: I should add that I've seen most of the wizard control tutorials out there, but none of them seem to address what I'm trying to do. In particular, the need to save and retrieve data between steps, and how to keep it from retrieving that same data again if the step is revisited.

A: 

What you've done sounds reasonable.. Can you be more specific about the problem you are having?

One thing about the wizard control, as your workflow gets more and more complex I think the coupling between your workflow state and the wizard SelectedViewIndex becomes problematic. For this reason I eventually separate them. I will usually use a state/statemachine pattern, where the current workflow state is used to determine the appropriate wizard view index (but not vice-versa).

If you're looking for examples on how to implement a state machine, I have a test app out there that walks through dialogs like a wizard control, except using javascript. Check out http://main(dot)test.wishpot.com/WaveDataCollection.Frank/, after you get to the page CollectSamples.aspx, go ahead and view source, then start reviewing at the GotoState function.

State machines are plumbed a bit different in C#, the main difference being the state object is an abstract class with a fixed number of event handlers, which each state inheriting from that class implementing each handler (some perhaps throwing an exception). With javascript we don't need the abstract state class... Also, doing this serverside, you're going to need to be able to map from a state ID stored in your database to a state class.

Frank Schwieterman
It's not necessarily a problem. I was just concerned over how complex the solution needed to be to get the results I was after. I wasn't sure if there was a simpler way to accomplish the same goal. Do you have any other info/links on implementing state machines using server controls?
Jeremy Cantrell
Any guide on writing state machines... Unfortunately the introduction I read was C specific (Miro Samek's book). The book "Refactoring to Patterns" probably has good treatment on it, but I don't have a copy to verify it covers that particular pattern well.
Frank Schwieterman