Introduction
We use Date Time Format in a dd/mm/yyyy using Ajax Tool Kit 4.0
Background
Some problem using DateTimeFormat in a dd/mm/yyyy with using AjaxToolKit 4.0. mostly programmer avoid to using calender extender due to some reason.
Using the Code
Firstly you add up CultureInfo class through System.Diagnostic name space,then use the TRYPARSExact method for correct date time format.so Don,t Forget to add up a property name of "CULTURE NAME" in MaskEditExtender (Below which is mark in a REd colour).
stStartDate = txtStartDate1.Text;
stEndDate = txtEndDate1.Text;
CultureInfo enBR = new CultureInfo("pt-BR");
DateTime startDate = new DateTime();
DateTime endDate = new DateTime();
if(txtStartDate1.Text == "__/__/____" && txtEndDate1.Text =="__/__/____")
{ }
if(txtStartDate1.Text != "__/__/____" || txtEndDate1.Text !="__/__/____")
{
if (txtStartDate1.Text != "__/__/____" && txtEndDate1.Text !="__/__/____")
{
if (DateTime.TryParseExact(stStartDate,"dd/MM/yyyy",
enBR,DateTimeStyles.None,out startDate)
&& DateTime.TryParseExact(stEndDate,"dd/MM/yyyy",
enBR,DateTimeStyles.None,out endDate) )
{
}
}
}
<cc1:MaskedEditValidator ID="MaskedEditValidator3" runat="server"
ControlExtender="MaskedEditExtenderSD2" ControlToValidate="txtStartDate1"
CssClass="RedLabel" Display="Dynamic" EmptyValueBlurredText="*"
ErrorMessage="MaskedEditValidator10" InvalidValueBlurredMessage="Invalid Date"
InvalidValueMessage="Valid Start of Date required" IsValidEmpty="False"
ValidationExpression="^\d{2}/\d{2}/\d{4}$" ValidationGroup="Form">(dd/mm/yyyy)
</cc1:MaskedEditValidator>
<cc1:CalendarExtender ID="CalendarExtenderSD2" runat="server" Enabled="True"
Format="dd/MM/yyyy" PopupButtonID="ImageButtonCalendar1"
TargetControlID="txtStartDate1"></cc1:CalendarExtender>
<cc1:MaskedEditExtender ID="MaskedEditExtenderSD2" runat="server"
ClearMaskOnLostFocus="False" Enabled="True" Mask="99/99/9999" MaskType="Date"
TargetControlID="txtStartDate1" CultureAMPMPlaceholder=""
CultureCurrencySymbolPlaceholder="" CultureDateFormat=""
CultureDatePlaceholder="" CultureDecimalPlaceholder=""
CultureThousandsPlaceholder="" CultureTimePlaceholder="" CultureName="pt-BR">
</cc1:MaskedEditExtender>
Points of Interest
It is so simple to use ajaxtoolkit for a datetime format.
Not too much lengthy code to write for date time format
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.