locked
Datepicker RRS feed

  • Question

  • User66371569 posted

    I have 2 textboxs inside gridview from to<br>

    how to show datepicker i want just month and year format Jan-2019 but i want it same hotels resrevation when shows from in to cant show date before from
    forexample if i choose Jan-2019 in from textbox i cant choose december-2018 in to textbox

    Thank you so much
    Friday, January 18, 2019 1:42 PM

All replies

  • User475983607 posted

    Explain what date picker you are using and provide enough code to reproduce this issue.

    thepast

    forexample if i choose Jan-2019 in from textbox i cant choose december-2018 in to textbox

    ASP.NET Web Forms has validation controls.  One is the compare validator which can be used to validate the to and from dates.

    https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.comparevalidator?view=netframework-4.7.2

    Friday, January 18, 2019 3:06 PM
  • User839733648 posted

    Hi thepast,

    According to your description, I suggest that you could use Jquery-UI. 

    You could see tha sample from the link: http://jqueryui.com/datepicker/#date-range 

    You should also read:

    http://api.jqueryui.com/datepicker/#option-minDate 

    http://api.jqueryui.com/datepicker/#option-maxDate 

    http://api.jqueryui.com/datepicker/#option-onClose 

    <head runat="server">
        <title></title>
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        <script>
            $(function () {
                var dateFormat = "mm/dd/yy",
                    from = $("#from")
                        .datepicker({
                            defaultDate: "+1w",
                            changeMonth: true,
                            numberOfMonths: 3
                        })
                        .on("change", function () {
                            to.datepicker("option", "minDate", getDate(this));
                        }),
                    to = $("#to").datepicker({
                        defaultDate: "+1w",
                        changeMonth: true,
                        numberOfMonths: 3
                    })
                        .on("change", function () {
                            from.datepicker("option", "maxDate", getDate(this));
                        });
    
                function getDate(element) {
                    var date;
                    try {
                        date = $.datepicker.parseDate(dateFormat, element.value);
                    } catch (error) {
                        date = null;
                    }
    
                    return date;
                }
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                From<asp:TextBox runat="server" ID="from"></asp:TextBox>
                to<asp:TextBox runat="server" ID="to"></asp:TextBox>
            </div>
        </form>
    </body>
    </html>
    

    result:

    Best Regards,

    Jenifer

    Tuesday, January 22, 2019 2:32 AM