Asked by:
Stop auto selection after postback

Question
-
User-284642143 posted
I have a page which allows you to select a date from Multi date picker (http://dubrox.github.io/Multiple-Dates-Picker-for-jQuery-UI) and add the selected date to another control. Heres some of the code
$(document).ready(function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
$('#mdp-demo').multiDatesPicker({
dateFormat: "y-m-d"
});
$("#body_Button").click(function () {
var dates = $('#mdp-demo').multiDatesPicker('getDates');
$('#mdp-demo').multiDatesPicker('resetDates', 'disabled');
})
}
});
The problem i have is after postback (once the user has selected a date, clicked the button to add to another control) today's date is automatically selected. i added this line$('#mdp-demo').multiDatesPicker('resetDates', 'disabled');
but made no difference.How could i stop todays date being selected after postback?
Wednesday, October 10, 2018 2:16 PM
All replies
-
User839733648 posted
Hi EssCee,
According to your description and code, I've made a sample on my side and could not reproduce your problem.
I've added the selected dates to the control successfully without today's date.
I'm not clear about your page design, so I've just designed a div to show the selected dates.
For more details, you could refer to the code below.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> <script src="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.js"></script> <link href="https://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css" rel="stylesheet" /> <link href="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.css" rel="stylesheet" /> <script type="text/javascript"> $(document).ready(function () { $('#mdp-demo').multiDatesPicker({ dateFormat: "y-m-d" }); $("#body_Button").click(function () { var dates = $('#mdp-demo').multiDatesPicker('getDates'); $("#dateinput").text(dates); }) }); </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div id="mdp-demo"></div> </ContentTemplate> </asp:UpdatePanel> <div id="dateinput" style="background-color: aquamarine"></div> <asp:button ID="body_Button" runat="server" text="Add" OnClientClick="return false;" /> </div> </form> </body> </html>
reslut:
Best Regards,
Jenifer
Thursday, October 11, 2018 6:47 AM -
User-284642143 posted
$('#mdp-demo').multiDatesPicker({ dateFormat: "y-m-d" });
Could you change the above code to the below
$('#mdp-demo').multiDatesPicker({ dateFormat: "y-m-d", minDate:0 });
As i figured thats the line that causes the issue. The minDate stops the calendar from showing past dates. On postback it selects today's date.
Thursday, October 11, 2018 10:28 AM -
User839733648 posted
Hi EssCee,
I've modified my code as you say but the code still runs well without auto selection.
The attribute minDate just defines a minimum date from where to pick dates.
From my point of view, maybe my page code has something different from yours, so I could not reproduce your problem.
If possible, please provide more detailed codes(including page code,JS code,plugin references) so that it will be easier for us to help with you.
Best Regards,
Jenifer
Friday, October 12, 2018 1:58 AM