Wednesday, June 07, 2006

NextStepIndex in a Wizard control

I've been using one of the new(ish) 2.0 Wizard controls in a project and it's been working nicely. That is, until I wanted to change it so that for one of the steps, you could leap out to a different page, update some other stuff, and then leap back in again to the step you were at before.

When coming back to the page and starting off at step number 2, I found that clicking the previous button didn't take me to step 1 as I expected (and wanted). A quick bit of breakpoint-setting and debugging later, I found that in the event handler, the NextStepIndex wasn't 0 (i.e. the first step), it was 1. Thus clicking the previous button simply left me on the second step.

This actually makes complete sense when placed in context, which a post on this thread was able to do for me. It's not previous in the sense of the last physical step as laid out in the .aspx file; it's previous in the sense of the last step in the history of your moves through the wizard. Since I was effectively starting off with a fresh copy of the wizard when coming back to the page, there was no history, and thus there was no previous step for me to go back to.

In the end, the solution is simply to specify what step you want next based on the CurrentStepIndex in the relevant event handler. Simple!

No comments: