Bonjour,

Mon CustomValidator ne marche que quand je mets une date dans le TextBox. Si je ne mets pas de date, c'est comme s'il était inexistant : fonction javascript n'est pas lancée et pas de message d'erreur associé à ce CustomValidator...
Pourtant, je vois bien ce CustomValidator dans le code HTML côté client...

Voici mon code ASP.NET :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
<td style="text-align:left;padding-left:4px;vertical-align:middle;">
    <asp:textbox id="DateRecupField" runat="server" onKeyPress="IsPosInteger(this);" onKeyUp="add(this);"></asp:textbox>
    <asp:CustomValidator id="DateRecupCustomValidator" runat="server" ControlToValidate="DateRecupField" ClientValidationFunction="csDateRecupValidatorCheck" Display="Dynamic" ValidationGroup="wfValidation" ErrorMessage="" Text="*"></asp:CustomValidator>
    <asp:RangeValidator ID="DateRecupRangeValidator" runat="server" ErrorMessage="" ControlToValidate="DateRecupField" Type="Date" ValidationGroup="wfValidation" Text="*" MinimumValue="01/01/1901" MaximumValue="12/12/2050"></asp:RangeValidator>
</td>
et ma fonction javascript appelée par le CustomValidator :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
<script type="text/javascript">
 
    function csDateRecupValidatorCheck(sender, args)
    {   
        alert('yop');
        var tableau = document.getElementById("<%=MaterielGrid.ClientID%>").getElementsByTagName("td");
        for (var i = 9; i < tableau.length ; i++)
        {
            chk = tableau[i].getElementsByTagName("input");
            alert(chk[0].checked+" "+i);
            if((chk[0].checked == true) && (document.getElementById("<%=DateRecupField.ClientID%>").value==""))
            {
                args.IsValid = false;
                return;
            }
            i=i+4;
        }
        args.IsValid = true;
        return;  
    }
 
</script>
Merci de m'éclairer!