How do I use Ajax MaskedEdit with a specific date format?
We have a text box where the user can enter a date. Permissible Effective Date:
. After going through all the problems, I think that
is the best choice. But I have some problems with this. Below is my ASPX code,
<div> Date: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:MaskedEditExtender ID="TextBox1_MaskedEditExtender" runat="server" CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True" Mask="99/99/9999" MaskType="Date" TargetControlID="TextBox1"> </asp:MaskedEditExtender> <asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox1" Format="MM/dd/yyyy"> </asp:CalendarExtender> </div>
Here are my questions:
- After adding
, when I take the date from the calendar, it won't write to the textbox.
- When I enter some date in the textbox, it becomes 01-01-2011 and not 01/01/2011, which is what I want.
- Should I use
? As I want to make sure the date like 02/29/2011 is not valid.
source to share
Your code is correct. I try it myself and everything works fine.
So, I suggest you try this code in a separate project solution to see if there is another problem.
About 3rd question, maybe you need to use MaskedEditValidator if you need to validate the entered date. You should use CompareValidator if you need to compare some dates, for example.
Here's a good example of using MaskedEditValidator:
<ajaxToolkit:MaskedEditValidator ID="MV_Date" runat="server" ControlToValidate="TextBox1" ControlExtender="TextBox1_MaskedEditExtender" InvalidValueMessage="Invalid Date" IsValidEmpty="False" />
source to share