I have a SharePoint DateTimeControl inside of an UpdatePanel. The issue I am experiencing is that when a postback occurs inside the panel the hour section of the DateTimeControl always gets reset to 12.

I have EnableViewState set to true on the control but it still is reset on postback.

Does anyone know how to make this behavior stop happening?

<SharePoint:DateTimeControl ID="WorkshopStartField" runat="server" CssClassTextBox="textbox" EnableViewState="true"/>



I ended up doing this: I added a hidden asp textbox, which the value does persist between postbacks, and when the hour dropdown changes i put the selected value into the textbox. Then on page load of the panel I check if the value in the textbox is different than that in the hour dropdown and if it is I set the selected value in the dropdown to be what is in the textbox. Super clunky, but it works.

$startHourSelectControl = $('#<%= WorkshopStartField.Controls[1].ClientID %>');
$startHourBox = $('#<%= StartHourHolder.ClientID %>');

if ($startHourBox.val() !== $startHourSelectControl.val()) {
   //if the start hour is different than the value held in the text box, then the page has posted back and lost the drop down value
   //set it back to what it was before the postback

$startHourSelectControl.change(function () {
   //if the start hour dropdown is changed, set the text box to have the same value

There is a Microsoft bug in SharePoint DateTime Control. This DateTimeControl loses state during postbacks, specifically of the hour. I struggled a bit to get this work around because it doesn’t work even if I put enableviewstate=”true” in the control. However I happened to get this work by adding this line of code in a event that caused the postback. It could be any method/Event, in my case, it is SelectedIndexChanged event:

 if (dtcDateTime< DateTime.Today)
 //Don’t do anything

Just be doing this, it maintains the value of the control during postback. https://spreflections.wordpress.com/2009/07/09/sharepoint-datetime-control/

  • Thanks for the suggestion. I don't really understand how that would have worked, but I have so many things causing the page to panel to postback that I didn't want to add a bunch of javascript calls. – Bjorn W Feb 24 '16 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.