how to display server side dates in jquery datepicker?

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="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="stylesheet" type="text/css"/>
         <link href="./themes/sunny/jquery.ui.all.css" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="stylesheet" type="text/css"/>
         <script src="./js/jquery.min.js"></script>
         <link rel="stylesheet" href="./demos/demos.css" rel="nofollow noreferrer noopener">    
<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> 

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 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() %>')

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply