How to create a fully validated asp.net calendar control - Digital Tool Factory blog How to create a fully validated asp.net calendar control - Digital Tool Factory blog

How to create a fully validated asp.net calendar control

The Problem: You have to have a fully validated date box. The dates must be valid dates and there must be data entered in the field.

The Cause: Not a problem really, I wind up rewriting it slightly differently each time. I thought I would put a definitive version here.

The Solution: Use this code
<asp:TextBox ID=”tbDate” runat=”server” CssClass=”body” />
<ajaxToolkit:MaskedEditExtender ID=”meeDate” runat=”server”
TargetControlID=”tbDate”
Mask=”99/99/9999″
MessageValidatorTip=”true”
OnFocusCssClass=”MaskedEditFocus”
OnInvalidCssClass=”MaskedEditError”
MaskType=”Date”
DisplayMoney=”Left”
AcceptNegative=”Left”
ErrorTooltipEnabled=”True” />
<ajaxToolkit:CalendarExtender ID=”ceDate” runat=”server” TargetControlID=”tbDate” PopupButtonID=”imgDate” />
<asp:RequiredFieldValidator ID=”rfvDate” runat=”server” ControlToValidate=”tbDate”
Display=”none” ErrorMessage=”<b>Required Field Missing</b><br />You must supply a date”
SetFocusOnError=”true” ValidationGroup=”MainB” />
<ajaxToolkit:ValidatorCalloutExtender ID=”vceDate” runat=”server” TargetControlID=”rfvDate” Width=”300″ />

<asp:CompareValidator ID=”compVDate” runat=”server” ValidationGroup=”MainB”
ControlToValidate=”tbDate” Display=”None” ErrorMessage=”<b>Required Field Missing</b><br />You must supply a valid date”
Operator=”DataTypeCheck” Type=”Date” />
<ajaxToolkit:ValidatorCalloutExtender ID=”vceCompDate” runat=”server” TargetControlID=”compVDate” Width=”300″ />
<asp:ImageButton runat=”Server” ID=”imgDate” ImageUrl=”img/icon_calendar.gif” AlternateText=”Click to show calendar” />

That’s it!

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog

 

Written By Steve French

 

Leave a Reply

Your email address will not be published. Required fields are marked *






Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.