Click here to Skip to main content
Click here to Skip to main content

DateTimeFormat DD/MM/YYYY in Ajax tool kit 4.0

, , 24 Mar 2009
Rate this:
Please Sign up or sign in to vote.
The big problem using date time format in dd/mm/yyyy using ajax tool kit 4.0

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)

About the Authors

Jason Troitsky

United Kingdom United Kingdom
No Biography provided

No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 PinmemberRay Hayes24-Mar-09 8:52 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 24 Mar 2009
Article Copyright 2009 by Jason Troitsky, zuhair haroon khan software programmer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid