Skip to main content

Search and Top Navigation

#8434 closed bug (duplicate)

Opened July 09, 2012 10:28PM UTC

Closed July 10, 2012 04:48PM UTC

Last modified July 10, 2012 04:48PM UTC

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.

Attachments (0)
Change History (4)

Changed July 10, 2012 02:36AM UTC by scottgonzalez comment:1

owner: → 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.

Changed July 10, 2012 04:32PM UTC by Mr. Jefferson comment:2

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.

Changed July 10, 2012 04:48PM UTC by scottgonzalez comment:3

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.

Changed July 10, 2012 04:48PM UTC by scottgonzalez comment:4

Duplicate of #6228.