Shahid Shahid - 5 months ago 31
jQuery Question

Datepicker ASP.NET

I am new to jquery, How do we make the date to appear in the textbox on the click of an button using jquery and ASP.NET? The calendar apears but it disappears very fast works fine with a textbox? What else do i need to include in the script of my button?
I have used this function

<script type="text/javascript" language="javascript">
$(document).ready(dateselect)
function dateselect()
{
var date1 = $("#Button1").datepicker();
}
</script>
<asp:Button ID="Button1" runat="server" Text="Button" />

Answer

Javascript:

<script type="text/javascript">
 $(function() {
        $("#<%= txtFrom.ClientID %>").datepicker({
            showmonth:true,
            autoSize: true,
            showAnim: 'slideDown',
            duration: 'fast'
        });

        $("#<%= ImageButton1.ClientID %>").click(function() {
          $("#<%= txtFrom.ClientID %>").datepicker('show');
        });
    });
</script>

Code:

<asp:TextBox ID="txtFrom" MaxLength="10" runat="server" ToolTip="Enter From Date">
</asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/clock_add.gif" />

Reference jquery forum

Edit 1

Change this function

 $("#<%= ImageButton1.ClientID %>").click(function() {
          $("#<%= txtFrom.ClientID %>").datepicker('show');
        });

to

 $("#<%= ImageButton1.ClientID %>").click(function() {
          $("#<%= txtFrom.ClientID %>").datepicker('show');
          return false;
        });

or

  $("#<%= ImageButton1.ClientID %>").click(function(event) {
          $("#<%= txtFrom.ClientID %>").datepicker('show');
          event.preventDefault();
        });

Edit 2

$("#txtStartDate").datepicker({
  showOn: "both",       
  onSelect: function(dateText, inst){
     $("#txtEndDate").datepicker("option","minDate",
     $("#txtStartDate").datepicker("getDate"));
  }
});

Source :
Restrict date in jquery datepicker based on another datepicker or textbox

Comments