Posted: 6/21/2011
I added a few fields in the 1st step of the creat user wizard. I added required field validators to them and they worked fine. I added a second step. I added required field validators to them, but they are not working. The step is allowed to complete with the text boxes empty. Here is the code from the first field:
<td align="right" style="width: 128px"> <asp:Label ID="FnLabel" runat="server" AssociatedControlID="FnTxtBox" Text="First name:"></asp:Label> </td> <td align="left"> <asp:TextBox ID="FnTxtBox" runat="server" Height="22px" Width="128px"></asp:TextBox> <asp:RequiredFieldValidator ID="FnRequired" runat="server" ControlToValidate="FnTxtBox" ErrorMessage="First name is required." ValidationGroup="CreateUserWizard1" Display="Dynamic">*</asp:RequiredFieldValidator> </td>
Does anyone why this is?
than you in advance
Posted: 6/22/2011
Hi Mike,
The snippet you send is ok, but i need to see the attributes of your buttons, "Back" and "Next" button.
But as you describe i think i know whats the problem. You need to override the first step of your wizard's button using <StartNavigationTemplate>, and if you are using sidebar buttons, then you should add your code in SideBarButtonClick event of your control and check the stepId you are currently in. This will validate the page with the valdiation group in parameters, and if the page is not valid it cancels the event. Remember to wire up the wizzard_SideBarButtonClick event in your <asp:Wizard> tag.
<StepNavigationTemplate> <asp:Button ID="btnBack" runat="server" CssClass="myWizButton" Text="Back" CommandName="GoPrevious" /> <asp:Button ID="btnNext" runat="server" CssClass="myWizButton" CommandName="GoNext" Text="Next" CausesValidation="true" ValidationGroup="wizzardValidator" /> </StepNavigationTemplate>
Important part is CommandName, and do not forget to set the property CauseValidation = "true" and to set up the ValidationGroup="yourValidationGroup".
protected virtual void wizzard_SideBarButtonClick(object sender, WizardNavigationEventArgs e) { Page.Validate("wizzardValidator"); if (!Page.IsValid) { e.Cancel = true; } }
Best Regards,
Gjorgji Dimitrov
Posted: 7/2/2011
THANKS yet again. works great!