title: JQuery UI inline DatePicker loses date after ASP.NET postback
body: <p>I have an inline DatePicker (Week-Picker) initiaized as follows, which on Select fires a ASP.NET click event. It functions fine and my ASP code does it's part, however if I select a date for ex: after advancing the month by the DatePicker's next/prev buttons, when the page refreshes after postback, the DatePicker returns to the current month...Also it loses the selected startDate / endDate Range in the selectCurrentWeek() method here.</p>
  
  <pre><code>    var startDate;
      var endDate;
      var selectCurrentWeek = function () {
          window.setTimeout(function () {
              $('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
          }, 1);
      }
  
  $('.week-picker').datepicker({
          showOtherMonths: true,
          selectOtherMonths: true,
          firstDay: 1,
          onSelect: function (dateText, inst) {
              var date = $(this).datepicker('getDate');
              startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1);
              endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
              var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;
              $('#txtDP1').val($.datepicker.formatDate(dateFormat, date, inst.settings));
              selectCurrentWeek();
              DP1_Submit();
          },
          beforeShowDay: function (date) {
              var cssClass = '';
              if (date &gt;= startDate &amp;&amp; date &lt;= endDate)
                  cssClass = 'ui-datepicker-current-day';
              return [true, cssClass];
          },
          onChangeMonthYear: function (year, month, inst) {
              selectCurrentWeek();
          }
      });
  
          $('.week-picker .ui-datepicker-calendar tr').live('mousemove', function () { $(this).find('td a').addClass('ui-state-hover'); });
      $('.week-picker .ui-datepicker-calendar tr').live('mouseleave', function () { $(this).find('td a').removeClass('ui-state-hover'); });
  </code></pre>
  
  <p>The hidden field/button are:</p>
  
  <pre><code>&lt;asp:TextBox ID="txtDP1" runat="server" style="display:none;" /&gt;
  &lt;asp:Button ID="btnDP1" runat="server" Text="Go" style="display:none;"  /&gt;
  </code></pre>
  
  <p>I have tried using the setDate() method, and defaultDate property without success. Help? </p>