AJAX Validator firing before my CustomValidator?

Last post 05-19-2008 10:41 AM by Jonathan Shen – MSFT. 24 replies.

Sort Posts:

  • AJAX Validator firing before my CustomValidator?

    05-09-2008, 2:38 PM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

    I have a Wizard Control setup with mixed AJAX and Custom Validators.  My Custom Validators are only firing after the AJAX Validators have validated.  How can I make all of the validators fire at once?

  • Re: AJAX Validator firing before my CustomValidator?

    05-09-2008, 4:19 PM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

     Does this make sense?

  • Re: AJAX Validator firing before my CustomValidator?

    05-12-2008, 7:51 AM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

     anyone?

  • Re: AJAX Validator firing before my CustomValidator?

    05-13-2008, 8:58 AM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

     Ok, well is there an AJAX validator, other than the MaskEdit, that I should try?

  • Re: AJAX Validator firing before my CustomValidator?

    05-13-2008, 1:37 PM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

     bump

  • Re: AJAX Validator firing before my CustomValidator?

    05-14-2008, 2:32 PM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

     I really need some help on this...

  • Re: AJAX Validator firing before my CustomValidator?

    05-14-2008, 7:09 PM
    • Loading...
    • vicpal25
    • Joined on 03-08-2006, 11:33 PM
    • Posts 352

     Have you tried using a Validation Summary control? It will simulate exceptions (if any) at once.

    Victor A. Palma
  • Re: AJAX Validator firing before my CustomValidator?

    05-15-2008, 3:18 AM
    Answer

    Hi Bshannon,

    To validate all the controls on client, we shall call Page_ClientValidate() function on client.  It is a javascript function.   In additional, we can validate part of the controls.   In this situation, we shall first divide the controls into different ValidationGroup, then call the javascript  Page_ClientValidate(ValidationGroup name);

    Best regards,

    Jonathan

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: AJAX Validator firing before my CustomValidator?

    05-15-2008, 9:14 AM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

     The AJAX Validators are the ones firing first and they are Client Side, right?  So, client side is working, but it's stopping the Server Side Validators from firing?

  • Re: AJAX Validator firing before my CustomValidator?

    05-15-2008, 9:15 AM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

     Here are my Server Side Event Handlers...

        protected void stepWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                e.Cancel = true;
            }
        }

        protected void stepWizard_SideBarButtonClick(object sender, WizardNavigationEventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                e.Cancel = true;
            }

        }

        protected void stepWizard_PreviousButtonClick(object sender, WizardNavigationEventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                e.Cancel = true;
            }

        }
     

  • Re: AJAX Validator firing before my CustomValidator?

    05-15-2008, 9:50 AM

    Hi Bshannon,

    bshannon:
    The AJAX Validators are the ones firing first and they are Client Side, right?  So, client side is working, but it's stopping the Server Side Validators from firing?

    Yes.  If the page cannot pass the client validation, it won't postback.

    Best regards,

    Jonathan

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: AJAX Validator firing before my CustomValidator?

    05-15-2008, 9:53 AM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

     Can I force it to postback?

  • Re: AJAX Validator firing before my CustomValidator?

    05-15-2008, 9:59 AM

    Hi Bshannon,

    Since there are some not validated contents on your page, why do you force it to postback?   However, it is achievable by using __doPostBack("control's name which fired the event","");

    Best regards,

    Jonathan

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: AJAX Validator firing before my CustomValidator?

    05-15-2008, 10:14 AM
    • Loading...
    • bshannon
    • Joined on 10-03-2007, 7:42 PM
    • Posts 100

    Jonathan,

    Here's my code

    Javascript:
    function ValidateGroup(){
        $object("_PageRequestManager")._doPostBack( "", "" );
    }

    StepNavigationTemplate:
    <StepNavigationTemplate>
        <asp:Button ID="StepPreviousButton" OnClientClick="return ValidateGroup();" runat="server" CausesValidation="True" ValidationGroup="WizardValidationGroup" CommandName="MovePrevious" Text="Previous" CssClass="StepNav" />
        <asp:Button ID="StepNextButton" OnClientClick="return ValidateGroup();" runat="server" CausesValidation="True" ValidationGroup="WizardValidationGroup" CommandName="MoveNext" Text="Next" CssClass="StepNav" />
    </StepNavigationTemplate>

     

    ASP.NET:
    <table cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin-top: 10px;">
        <tr>
            <td class="subContentBox" style="width:80px; background-color: Transparent; text-align: right; vertical-align: middle;">First Name<sup>*</sup></td>
            <td style="padding-left: 10px; background-color: Transparent; text-align: left; vertical-align: middle;">
                <asp:TextBox runat="server" ID="FirstName" CssClass="TextControl" tabindex="1" CausesValidation="True" AutoPostBack="True" ValidationGroup="SSNStepValidationGroup" />
                <asp:CustomValidator runat="server" ID="FirstNameCustomValidator"
                    ValidationGroup="WizardValidationGroup"
                    OnServerValidate="RequiredField"
                    ControlToValidate="FirstName"
                    ErrorMessage="*FirstName"
                    Display="Dynamic"
                    ValidateEmptyText="True" />
            </td>
        </tr>
        <tr>
            <td class="subContentBox" style="width:80px; background-color: Transparent; text-align: right; vertical-align: middle;">Middle Initial</td>
            <td style="padding-left: 10px; background-color: Transparent; text-align: left; vertical-align: middle;">
                <asp:TextBox runat="server" ID="MiddleName" CssClass="TextControl" Columns="2" maxLength="1" tabindex="2" />
            </td>
        </tr>
        <tr>
            <td class="subContentBox" style="width:80px; background-color: Transparent; text-align: right; vertical-align: middle;">Last Name<sup>*</sup></td>
            <td style="padding-left: 10px; background-color: Transparent; text-align: left; vertical-align: middle;">
                <asp:TextBox runat="server" ID="LastName" CssClass="TextControl" tabindex="3" CausesValidation="True" AutoPostBack="True" ValidationGroup="SSNStepValidationGroup" />
                <asp:CustomValidator runat="server" ID="LastNameCustomValidator"
                    ValidationGroup="WizardValidationGroup"
                    OnServerValidate="RequiredField"
                    ControlToValidate="LastName"
                    ErrorMessage="*Last Name"
                    Display="Dynamic"
                    ValidateEmptyText="True" />
            </td>
        </tr>
        <tr>
            <td class="subContentBox" style="width:80px; background-color: Transparent; text-align: right; vertical-align: top;">SSN<sup>*</sup></td>
            <td style="padding-left: 10px; background-color: Transparent; text-align: left; vertical-align: middle;">
                <asp:TextBox runat="server" ID="SSNTextBox" CssClass="TextControl" Columns="15" tabindex="4" CausesValidation="true" AutoPostBack="true" ValidationGroup="WizardValidationGroup" />
                <ajaxToolkit:MaskedEditExtender ID="SSNMaskedEditExtender" runat="server"
                    TargetControlID="SSNTextBox"
                    Mask="999-99-9999"
                    MaskType="Number"
                    OnInvalidCssClass="TextControlInvalid"
                    OnFocusCssClass="TextControlFocus"
                    AutoComplete="False"
                    Enabled="True" />
                <ajaxToolkit:MaskedEditValidator ID="SSNMaskedEditValidator" runat="server"
                    ValidationGroup="WizardValidationGroup"
                    ControlToValidate="SSNTextBox"
                    ControlExtender="SSNMaskedEditExtender"
                    Display="Dynamic"
                    IsValidEmpty="False"
                    EmptyValueMessage="*SSN"
                    ErrorMessage="*SSN" />
                <asp:RegularExpressionValidator ID="SSNRegularExpressionValidator" runat="server"
                    ValidationGroup="WizardValidationGroup"
                    ErrorMessage="*Invalid SSN"
                    Display="Dynamic"
                    ControlToValidate="SSNTextBox"
                    ValidationExpression="^(?!000000000)\d{9}$" />
            </td>
        </tr>
        <tr>
            <td class="subContentBox" style="width:80px; background-color: Transparent; text-align: right; vertical-align: top;">Email</td>
            <td style="padding-left: 10px; background-color: Transparent; text-align: left; vertical-align: middle;">
                <asp:TextBox runat="server" ID="EmailTextBox" CssClass="TextControl" Columns="50" maxLength="50" tabindex="5" CausesValidation="True" AutoCompleteType="Email" />
                <asp:RegularExpressionValidator ID="EmailRegularExpressionValidator"
                    runat="server"
                    ControlToValidate="EmailTextBox"
                    ErrorMessage="*Invalid Email"
                    Display="Dynamic"
                    ValidationGroup="WizardValidationGroup"
                    ValidationExpression="^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$" />
            </td>
        </tr>
    </table>

  • Re: AJAX Validator firing before my CustomValidator?

    05-15-2008, 11:10 AM

    Hi Bshannon,

    What's your problem ?   To postback without validation, please set the Control's CausesValidation="false".  For example,

    <asp:Button ID="Button2" runat="server" Text="Button" CausesValidation="false"/>

    Best regards,

    Jonathan

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.