Opened 11 years ago

Closed 11 years ago

Last modified 11 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:

Description

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: http://stackoverflow.com/q/9470736/412107.

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">
			<ContentTemplate>
				<asp:DropDownList ID="dropdown" runat="server" AutoPostBack="true">
					<asp:ListItem Value="Foo" />
					<asp:ListItem Value="Bar" />
				</asp:DropDownList>
				<asp:TextBox ID="text" runat="server" ClientIDMode="Static" />
			</ContentTemplate>
		</asp:UpdatePanel>
		<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' });
				}
			}

		</script>

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 11 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 11 years ago by Mr. Jefferson

Status: pendingnew

I've reproduced the problem without ASP.NET in this jsfiddle: http://jsfiddle.net/tzDnZ/2/

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 11 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 11 years ago by Scott González

Duplicate of #6228.

Note: See TracTickets for help on using tickets.