Use of calendar web control

  • Thread starter Thread starter Lloyd Sheen
  • Start date Start date
L

Lloyd Sheen

I am having a problem with the month/day settings of the calendar control.
I have a SQL Server 2000 providing a date which is displayed in a text box
correctly. There is a button beside the textbox to allow the user to popup
the calendar control.

There are 2 problems.

1. The month/date are reversed when setting the date in the calendar as
follows:

Me.Panel1.Visible = True
Dim pdDate As Date
pdDate = Convert.ToDateTime(Me.originatingDate.Text)
Calendar1.SelectedDate = pdDate


2. The opposite of the above when attempting to put selected date back to
the text box.

Dim pdDate As Date = Calendar1.SelectedDate
originatingDate.Text = CStr(pdDate)
Me.Panel1.Visible = False


Any ideas?

Lloyd Sheen
 
The basic problem is that the calendar control is using a different
CultureInfo object for formatting than your conversion strings. Web forms
follow the CultureInfo on
System.Threading.Thread.CurrentThread.CurrentCulture. You should be sure to
use its DateTimeFormat.ShortDatePattern in the conversion of dates to
strings and back.
Convert.ToDateTime(string,
System.Threading.Thread.CurrentThread.CurrentCulture)
Date.ToShortDateString()

Did you know that there are a number of fully debugged and feature rich
DateTextBoxes with popup calendars available? You can see them at the
www.asp.net Control Gallery, www.123aspx.com, and www.411asp.net. In fact,
unless you are trying to learn how to do this yourself, you are wasting time
because of the options available. Mine is Peter's Date Package
(http://www.peterblum.com/datecontrols/home.aspx). It handles culture issues
like this one. Its Calendar updates on the client side as you click on dates
or change months.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
Back
Top