Search code examples
asp.netajaxcontroltoolkitcustomvalidator

asp.net CustomValidator fires, but ServerValidateEventArgs Value always empty


I'm having a problem implementing a CustomValidator, I have multiple TextBoxes with a MaskedEditExtender, they all should contain a date ("dd-MM-yyyy"). To check this date I want to use the CustomValidator, but the e.Value passed to my MyValidate function is always empty, while the TextBox is not.

code:

<asp:TextBox ID="Gereed" runat="server" CssClass="date" />
<asp:CustomValidator ID="cd1" runat="server" TargetControlID="Gereed" />
<asp:MaskedEditExtender ID="md1" runat="server" TargetControlID="Gereed" 
     Mask="99-99-9999" ClearMaskOnLostFocus="false"/>

code behind:

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    cd1.ValidateEmptyText = True
    AddHandler cd1.ServerValidate, AddressOf ValidateDate 
End Sub
Protected Sub ValidateDate(ByVal sender As Object, ByVal e As ServerValidateEventArgs)
    e.IsValid = MyValidate(e.Value, "dd-MM-yyyy")
End Sub

I had a ClientValidationFunction that has the same problem.

Does anyone know a solution to this? I guess I'm missing something, but I don't know what, a similar solution in another website works perfectly.


Solution

  • TargetControlID is not a property of CustomValidator, it should be ControlToValidate. Somehow there was no errormessage, normal Validators throw an exception if ControlToValidate was not found, but the CustomValidator does not.