Tags

,

A simple example to validate in wizard control

<asp:TextBox ID=”BookTravelName” CssClass=”textbox” runat=”server” />
<asp:RequiredFieldValidator ID=”RequiredFieldValidator1″ runat=”server” ControlToValidate=”BookTravelName” ErrorMessage=”You must enter your name.” ValidationGroup=”ContactInformationEnableClientScript=”False”></asp:RequiredFieldValidator>
I disable the clientscript here as it put the mouse back to the top of the page

<asp:ValidationSummary ID=”ValidationSummary1″ runat=”server” ShowSummary=”True” ShowMessageBox=”false” EnableClientScript=false ValidationGroup=”ContactInformation” />

Then you need put CausesValidation=”true” ValidationGroup=”ContactInformation” on the next button

<StartNavigationTemplate>
                <p>
                    <cc:AjaxLinkButton ID=”TravelWizardCancelButton” CssClass=”bumpright” CommandName=”Cancel” ClickFunction=”ShowLoading” ClickParameters=”this,’TravelWizardStatus'” Text=”Cancel” runat=”server” />
                    <cc:AjaxLinkButton ID=”TravelWizardStartButton” cssClass=”wide_button partial_submit bumpleft” CommandName=”MoveNext” ClickFunction=”ShowLoading” ClickParameters=”this,’TravelWizardStatus'” Text=”Next” runat=”server” CausesValidation=”true” ValidationGroup=”ContactInformation“/>
                    <cc:AjaxImage ID=”TravelWizardStatus” ImageUrl=”~/App_Themes/Theme/Images/Spacer.gif” ResolveClientID=”false” CssClass=”partial_submit_status bumpleft” runat=”server” />
                </p>
</StartNavigationTemplate>

In your code, put the Page.isValid on the next button event:

        protected void WizardNext_Click(Object sender, WizardNavigationEventArgs e)
        {

            Page.Validate(“ContactInformation“);
            if (!Page.IsValid)
            {
                e.Cancel = true;
                return;
            }

…..

Advertisements