[Solved] Ajax CalendarExtender not to select previous year in ASP.Net

Last Reply 2 months ago By dharmendr

Posted 2 months ago

I am not able to select date before the year of 2000. I also used masked extender becoz i wanted masking in textbox. Below i have attached code which i have tried 

<asp:TextBox ID="txtOrientationDate" runat="server" onclick="this.focus();this.select()" AutoCompleteType="None" MaxLength="10" ValidateRequestMode="Inherit" width="90px" TabIndex="450" cssclass="textbox"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ControlToValidate="txtOrientationDate" ValidationExpression="^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$"
    ErrorMessage="Invalid date format." ForeColor="Red" ValidationGroup="Group1" />
<ajax:CalendarExtender ID="CalendarExtender2" TargetControlID="txtOrientationDate"  Format="MM/dd/yyyy"  runat="server" >
</ajax:CalendarExtender>
<asp:MaskedEditExtender ID="MaskedEditExtender1" ClearMaskOnLostFocus="false" runat="server" PromptCharacter=" " TargetControlID="txtOrientationDate" Mask="99/99/9999" Enabled="true" MaskType="Date"  
    MessageValidatorTip="true" ErrorTooltipEnabled="True" CultureName="en-GB" AutoComplete="False" UserDateFormat="MonthDayYear">
</asp:MaskedEditExtender>

my code is working properly but the thing is that m not able to select date before the yera 2000

You are viewing reply posted by: dharmendr 2 months ago.
Posted 2 months ago

Hi JennyD6856,

Adding MaskedEditValidator to your code will work.

Check this example. Now please take its reference and correct your code.

HTML

<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
<asp:TextBox ID="txtOrientationDate" runat="server" onclick="this.focus();this.select()"
    AutoCompleteType="None" MaxLength="10" ValidateRequestMode="Inherit" Width="90px"
    TabIndex="450" CssClass="textbox"></asp:TextBox>
<ajax:CalendarExtender ID="CalendarExtender2" TargetControlID="txtOrientationDate"
    Format="MM/dd/yyyy" runat="server">
</ajax:CalendarExtender>
<ajax:MaskedEditExtender ID="MaskedEditExtender1" ClearMaskOnLostFocus="false" runat="server"
    PromptCharacter=" " TargetControlID="txtOrientationDate" Mask="99/99/9999" Enabled="true"
    MaskType="Date" MessageValidatorTip="true" ErrorTooltipEnabled="True" CultureName="en-GB"
    AutoComplete="False" UserDateFormat="MonthDayYear">
</ajax:MaskedEditExtender>
<ajax:MaskedEditValidator runat="server" ID="MaskedEditValidator1" ControlToValidate="txtOrientationDate"
    ControlExtender="MaskedEditExtender1" Display="dynamic" IsValidEmpty="False"
    InvalidValueMessage="*" />

Screenshot