how to display server side dates in jquery datepic

2020-05-09 01:46发布

问题:

i have a textbox1 in my asp.net webform which shows the server side date :

i want the user would not select date using jquery datepicker earlier than the date in the textbox1

i m using the following code to show jquery calendar in other textbox2 :

<link href="./themes/sunny/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
         <link href="./themes/sunny/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
         <script src="./js/jquery.min.js"></script>
         <link rel="stylesheet" href="./demos/demos.css">    
<script src="./js/jquery-ui.min.js"></script> 

    <script type="text/javascript">  
       $(document).ready(function() {    

      $(".datepicker").datepicker({    

          buttonText: 'Select date:',    
          firstDay: 1,  
          buttonImage: "./demos/datepicker/images/calendar.gif",  
          buttonImageOnly: true,    
          showOn: 'both',    
          showAnim: 'fadeIn',    
          minDate: '0',
          dateFormat: 'dd-M-yy',    
          onSelect: function() { $(this).trigger("onchange", null); }    
      });    
      });   
    </script> 

回答1:

minDate: new Date('<%= textbox1.Text %>')

Assuming your textbox1 contains a valid date format. Do you actually need textbox1 though? If you just want the server date you can do:

minDate: new Date('<%= DateTime.Now.ToString() %>')