CustomValidator inside a DetailsView

Discussion in 'ASP .Net Web Controls' started by Paulo Costa, Jul 3, 2008.

  1. Paulo Costa

    Paulo Costa Guest

    Hi,

    I have, in a webform, a DetailView with 8 fields, 4 of them are required and
    I'm using a RequiredValidator with no problems, the other 4 must be all empty
    or all filled (cannot be some empty and other filled). To validate this I'm
    using a CustomValidator but with no sucess:
    - the event defined in the attribute OnServerValidate="OnValidateOverride"
    is not triggered;
    - the clientside function defined in the attribute
    ClientValidationFunction="GradeValidate" is triggered but in javascript i
    can´t reach the controls inside DetailsView template fields;

    if the textboxs and Validators are outside de Detailsview it works fine.
    Can someone give me a clue?
    Thanks in advance,

    Example:
    aspx:
    <script type="text/javascript" language="javascript">
    function TestValidate(source, args)
    {
    var obj = document.getElementById("<%=TestDetailsView.ClientID%>");
    ..........
    //the TestDetailsView is reached but the controls inside are not
    }
    </script>

    ...............

    <asp:TextBox ID="TextBox1" runat="server"/>
    <asp:TextBox ID="TextBox2" runat="server"/>
    <asp:CustomValidator ID="CustomValidatorTeste1" runat="server"
    OnServerValidate="OnValidateOverride" ClientValidationFunction="TesteValidate"
    ControlToValidate="TextBox1" ValidationGroup="testeGroup"
    ErrorMessage="Obrigatório preencher os restantes campos de override"/>
    <asp:CustomValidator ID="CustomValidatorTeste2" runat="server"
    OnServerValidate="OnValidateOverride" ClientValidationFunction="TesteValidate"
    ControlToValidate="TextBox2" ValidationGroup="testeGroup"
    ErrorMessage="Obrigatório preencher os restantes campos de override"/>
    <asp:LinkButton ID="InsertBtn" runat="server" Text="Testar"
    ValidationGroup="testeGroup" />

    codebehind:
    public void OnValidateOverride(object sender, ServerValidateEventArgs e)
    {
    e.IsValid = ((this.TextBox1.Text != string.Empty && this.TextBox2.Text !=
    string.Empty) ||
    (this.TextBox1.Text == string.Empty && this.TextBox2.Text ==
    string.Empty));
    }


    --
    Paulo
     
    Paulo Costa, Jul 3, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    5,216
  2. B. Chernick

    Customvalidator problem within Detailsview

    B. Chernick, Dec 4, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,774
    B. Chernick
    Dec 5, 2007
  3. Anton
    Replies:
    1
    Views:
    3,983
    miher
    Sep 6, 2009
  4. Trauckos

    CustomValidator inside Datagrid

    Trauckos, Oct 29, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    146
    Fernando Hunth
    Dec 10, 2004
  5. Feege
    Replies:
    0
    Views:
    493
    Feege
    Dec 20, 2005
Loading...

Share This Page