I am getting inconsistent date formats from the ASP.Net calendar control. Sometimes when I click the button I get "3/30/2006 12:00:00 AM" sometimes I get "30/03/2006 00:00:00". This is breaking my code. I have reproduced the problem in the code below (this demonstrates the problem it is not the code I want to use in real life). It does not occur on my development machine just on the production server.
<%@ Page Language="
vb" AutoEventWireup="false" Codebehind="testdate.aspx.
vb" Inherits="WebApplication1.testdate"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>testdate</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Calendar id="TestVisitDate" runat="server" BorderColor="Blue" FirstDayOfWeek="Monday">
<SelectorStyle BackColor="#C0C0FF"></SelectorStyle>
<DayStyle BackColor="White"></DayStyle>
<NextPrevStyle BackColor="#C0C0FF"></NextPrevStyle>
<DayHeaderStyle ForeColor="White" BackColor="CornflowerBlue"></DayHeaderStyle>
<SelectedDayStyle BackColor="#FFFF80"></SelectedDayStyle>
<TitleStyle BackColor="#C0C0FF"></TitleStyle>
<OtherMonthDayStyle BackColor="#E0E0E0"></OtherMonthDayStyle>
</asp:Calendar>
<asp:Button id="Button1" onclick="setdates" runat="server" text="Search By Date"></asp:Button>
<asp:Label id="VisitDate_Label" runat="server" Visible="True" />
</form>
</body>
</HTML>
Public Class testdate
Inherits System.Web.UI.Page
Dim VisitDate_value
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents VisitDate_Label As System.Web.UI.WebControls.Label
Protected WithEvents TestVisitDate As System.Web.UI.WebControls.Calendar
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Sub setdates(ByVal Sender As Object, ByVal E As EventArgs)
VisitDate_Label.Text = TestVisitDate.SelectedDate.ToString()
End Sub
End Class