Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#8434 closed bug (duplicate)

Wrong Month and Year Chosen when Open through ASP.NET Partial Postback

Reported by: Mr. Jefferson Owned by: Mr. Jefferson
Priority: minor Milestone: 1.9.0
Component: ui.datepicker Version: 1.8.21
Keywords: Cc:
Blocked by: Blocking:


If a datepicker is open during an ASP.NET partial postback through an UpdatePanel, and the datepicker's control is in that UpdatePanel, then the date chosen will have the wrong year and month. The year will either be 1899 or 1900. This is documented on Stack Overflow here:

Reproduction procedure:

Set up a new ASP.NET (I've seen this in both 2 and 4) that includes jQuery, jQueryUI, the necessary CSS, and this markup:

<asp:UpdatePanel ID="update" runat="server">
				<asp:DropDownList ID="dropdown" runat="server" AutoPostBack="true">
					<asp:ListItem Value="Foo" />
					<asp:ListItem Value="Bar" />
				<asp:TextBox ID="text" runat="server" ClientIDMode="Static" />
		<script type="text/javascript">
			$(document).ready(function ()
				$('#text').datepicker({ changeYear: true, showButtonPanel: true, yearRange: '-2:+2' });

			function pageLoad(sender, args)
				if (args._isPartialLoad == true)
					$('#text').datepicker({ changeYear: true, showButtonPanel: true, yearRange: '-2:+2' });


Get the focus to the dropdown, using the tab key if necessary. Press the b key to change the selection. Without doing anything else after this, click one of the next/previous month buttons at least once. If you click forward, you'll end up in January of the earliest year in the year dropdown (at time of writing with the above code, that's 2010). If you click backward, you'll end up in December, again with the earliest year in the dropdown. Then if you click a day, you end up with a date containing the displayed month and day but the year 1899 if you went back or 1900 if you went forward.

I've figured out a workaround where I supply a function for onChangeMonthYear and check to see if the year is 1899 or 1900. If so, I set the current date appropriately.

Change History (4)

comment:1 Changed 5 years ago by Scott González

Owner: set to Mr. Jefferson
Status: newpending

Issues dealing specifically with .net integration cannot be addressed in this bug tracker. If you can provide a reduced test case using just JavaScript, then we can look into this.

comment:2 Changed 5 years ago by Mr. Jefferson

Status: pendingnew

I've reproduced the problem without ASP.NET in this jsfiddle:

The key is to bring up the datepicker, destroy and recreate the input it's bound to, and then reinitialize the picker while it's still open. Its drawYear and drawMonth properties go to zero.

comment:3 Changed 5 years ago by Scott González

Resolution: duplicate
Status: newclosed

The problem you describe is not a situation you should ever be in. Removing the text field should destroy the datepicker. It doesn't because datepicker doesn't use the widget factory yet. But even once it does, you'll need to use jQuery to remove the text field, not .innerHTML.

comment:4 Changed 5 years ago by Scott González

Duplicate of #6228.

Note: See TracTickets for help on using tickets.