Why CustomValidator Fires Twice!

Last post 02-28-2008 10:14 AM by juliusklepacz@hotmail.com. 2 replies.

Sort Posts:

  • Why CustomValidator Fires Twice!

    01-25-2007, 6:01 PM
    • Participant
      1,266 point Participant
    • mhariri
    • Member since 11-15-2004, 8:35 PM
    • Posts 502

    Hi,

    I have a Formview with a customvalidator tied to one of the textboxes. I am using the Server_validate method and it is firing twice!

    int i =0;

    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)

    {

    i=i+1;

    if (i==1) { args.IsValid=true; } else {args.IsValid = false;}

    }

    <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="NumberTextBox"

    ErrorMessage="Credit Card information could not be validated. Please verify the information you provided"

    OnServerValidate="CustomValidator1_ServerValidate" ValidationGroup="G1">*</asp:CustomValidator>

    adds two to the value! Any ideas on what is wrong?

    Thanks,

    Mo

     

  • Re: Why CustomValidator Fires Twice!

    01-26-2007, 4:54 AM
    • Participant
      914 point Participant
    • Marian Kostal
    • Member since 01-10-2007, 11:33 PM
    • Banovce nad Bebravou, Slovakia
    • Posts 191
    Validators on page are fired when Page.Validate() method is called, so check whether you call this method in codebehind.
  • Re: Why CustomValidator Fires Twice!

    02-28-2008, 10:14 AM

    I am having the same problem. Inside a detailsview control, I have the following CustomValidator, and it's OnServerValidate handler fires twice. No explicit page validate called or anything unusual.

    Thanks.

    <asp:TemplateField HeaderText="Zone Name">

    <edititemtemplate>

    <asp:TextBox id="tbZoneName" runat="server" Text='<%# Bind("zone_name") %>' MaxLength="50" CssClass="required"></asp:TextBox>

    <asp:RequiredFieldValidator ID="reqZoneName" ControlToValidate="tbZoneName" runat="server" ErrorMessage="Zone Name is required" Display="dynamic" CssClass="errorText" EnableClientScript="false">*</asp:RequiredFieldValidator>

    <asp:CustomValidator ID="custValZoneName" ControlToValidate="tbZoneName" runat="server" OnServerValidate="CustomValidator_ZoneName_Exists" ErrorMessage="Zone Name already exists in the system - please specify a different Zone Name" Display="dynamic" CssClass="errorText" EnableClientScript="false">*</asp:CustomValidator>

    </edititemtemplate>

    </asp:TemplateField>

Page 1 of 1 (3 items)