DerekWatling
asked on
Date validation in ASP.NET 2.0
What is the best way to validate a date in ASP.NET 2.0? I have a TextBox control and want the date to be entered as yyyy/mm/dd and check that it is a valid date. I have been trying to use the AJAX MaskedEditExtender and MaskedEditValidator, but can't get this to work.
<asp:TextBox ID="tbDate" runat="server" />
<cc1:MaskedEditExtender ID="meeDate" runat="server" TargetControlID="tbDate" Mask="9999/99/99" MaskType="Date" CultureName="en:za" />
<cc1:MaskedEditValidator ID="mevDate" runat="server" ControlToValidate="tbDate" ControlExtender="meeDate" Text="Invalid date" Display="Dynamic"></cc1:Ma skedEditVa lidator>
can anyone help or suggest a better method?
<asp:TextBox ID="tbDate" runat="server" />
<cc1:MaskedEditExtender ID="meeDate" runat="server" TargetControlID="tbDate" Mask="9999/99/99" MaskType="Date" CultureName="en:za" />
<cc1:MaskedEditValidator ID="mevDate" runat="server" ControlToValidate="tbDate"
can anyone help or suggest a better method?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The MaskedEditExtender/Validat or were doing too many strange things. Have ended up writing my own JavaScript onfocus and onblur functions that do what I want.
You can ask here for question close: http:/Community_Support/General/newQuestionWizard.jsp
<asp:TextBox ID="tbDate" runat="server" />
<cc1:MaskedEditExtender ID="meeDate" runat="server" TargetControlID="tbDate" Mask="9999/99/99" MaskType="Date" CultureName="en:za" />
<cc1:MaskedEditValidator ID="mevDate" runat="server" ControlToValidate="tbDate"
Text="Invalid date" Display="Dynamic"></cc1:Ma
And add this function:
<script type="text/javascript">
function checkDate(source, clientside_arguments){
var checkDate = new Date(clientside_arguments.
clientside_arguments.IsVal
var dPart = clientside_arguments.Value
if(dPart[0]!=checkDate.get
dPart[1]!=checkDate.getMon
dPart[2]!=checkDate.getDat
clientside_arguments.IsVal
}
}
</script>