Disable previous Dates in Input Type Date (TextMode Date) using jQuery in ASP.Net

Last Reply 2 months ago By dharmendr

Posted 2 months ago

hello,

i am using this textbox with textmode datetime i want calender should start from current date means user cannot select previous dates it should be locked.

<asp:TextBox ID="txtdateofreservation" runat="server" TextMode="Date"></asp:TextBox>

 

You are viewing reply posted by: dharmendr 2 months ago.
Posted 2 months ago Modified on 2 months ago

Hi nauna,

To disable previous dates use min attribute.

Check this example. Now please take its reference and correct your code.

HTML

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        var today = new Date();
        var month = ('0' + (today.getMonth() + 1)).slice(-2);
        var day = ('0' + today.getDate()).slice(-2);
        var year = today.getFullYear();
        var date = year + '-' + month + '-' + day;
        $('[id*=txtdateofreservation]').attr('min', date);
    });
</script>
<asp:TextBox ID="txtdateofreservation" runat="server" TextMode="Date"></asp:TextBox>

Screenshot