Wednesday, March 28, 2012

The command MoveNext is not valid for the previous step, how to prevent this?

I am using WizardControl, on the first page, I have a validator, when user click next button or press enter, the validator will check the data and decide which step is the next step. But if I let it move to the last page, I will get error "The command 'MoveNext' is not valid for the previous step,...",I think it is because the last step doesn't have movenext button, and the validate event happens before nextbutton event, after it moves to the last step by code in the validator event, the nextbutton event need to be attached, but it could not find the object to attach. So I think I need a way to cancel the nextbutton event, any suggestion?

thanks!I am not sure what do you mean by "validator will check the data and decide which step is the next step." Can you post your code?
To cancel the nextbutton event you can do something like

protectedvoid Wizard1_NextButtonClick(object sender,WizardNavigationEventArgs e){
if(Wizard1.WizardSteps[e.CurrentStepIndex].StepType ==WizardStepType.Finish)
e.Cancel =true;
}


Thanks for reply.

On my first step page, there is a TextBox, user will type in their areacode, so I put a validator there to make sure user type in an areacode, and check if the areacode is valid, if it is valid, it will control which step is the next according the areacode. It looks like if I should put the code to decide which step to go into the NextButtonClick handler, but the validator event raises before the NextButtonClick event.
I saw that NextButtonClick event gets fired and saw the exception.
Canceling inside the event handler would not work in this scenario. So to avoid the firing of next button event completely wizardStep need to be templated. So you can get more control over the behavior of nextButton in the start step. Here is one example where next button click event doesnt get fired as the nextButton the the StartNavigationTemplate doesnt have the Command defined. I think that will server your purpose.

<asp:WizardID="Wizard1"runat="server">
<WizardSteps>
<asp:WizardSteprunat="server"Title="Step 1">
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<asp:CustomValidatorID="CustomValidator1"runat="server"ErrorMessage="CustomValidator"OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</asp:WizardStep>
<asp:WizardSteprunat="server"Title="Step 2">
</asp:WizardStep>
<asp:WizardStepID="Step3"runat="server">
</asp:WizardStep>
</WizardSteps>
<StartNavigationTemplate>
<asp:ButtonID="StartNextButton"runat="server"Text="Next"/>
</StartNavigationTemplate>
</asp:Wizard>

HTH,
Vishal

0 comments:

Post a Comment