Click here to Skip to main content
15,867,704 members
Articles / Web Development / ASP.NET

DateTimeFormat DD/MM/YYYY in Ajax tool kit 4.0

24 Mar 2009CPOL 39.8K   10   1
The big problem using date time format in dd/mm/yyyy using ajax tool kit 4.0
Image 1

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");

// check date Time Format 

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) )
                 {
                     // something 
                 } 
          }
  }

 

<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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
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.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Ray Hayes24-Mar-09 8:52
Ray Hayes24-Mar-09 8:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.