0

I am working on asp.net mvc application, After submitting selected date to the database , I want to refresh datepicker , I am able to refresh datepicker only pageload. I dont want to refresh whole page, I am having input field on popup (datepicker also). On submit button i am using ajax , so the whole page is not refreshed and datepicker holds previous selection, So how can i refresh datepicker.

This is jquery code i am using after ajax

function saveandContinue() {
    if (!validateManageRequestmodel())
        return;
    else
        $("#showerrormsg").hide();

    var model = getManageRequestmodel();
    $.ajax({
        type: "POST",
        url: "AddManageRequest",
        contentType: "application/json",
        data: $.toJSON(model),
        success: function (result) {
            debugger;
            if (result.Status == "ERROR") {
                showErrorMessage('showerrormsg', result.Result);
            }
            else if (result.Status == "OK") {
                showSuccessMessage('showerrormsg', 'Record saved successfully.');
                    **$(".datepicker").datepicker("refresh");**
                iIncrease++;
                if (gsaveParameter === 'add')
                    resetManageRequest();
                else if (gsaveParameter === 'edit') {
                    if (iIncrease < selectedIDs.length)
                        GetDataForEdit(selectedIDs[iIncrease]);
                    else {
                        $('#manageRequestModal').modal('hide');
                        onActionRefreshGrid();
                    }
                }
            }
        },
        error: function (error) {
            debugger;
            showErrorMessage('showerrormsg', error);
        }
    });
}

2 Answers 2

1

Demo link: 1
Demo link: 2

$(".datepicker").datepicker('setDate', null);
3
  • Thanks . but why refresh is not working like--$('.datepicker').datepicker('refresh'); Nov 15, 2016 at 17:51
  • your above code is refresh the datepicker thats good,but also here i want to disable past date in input box and disable future date in another input box, so disabling past and future date is not working, i also used your demo link:2 Nov 17, 2016 at 8:24
  • show me your datepicker past and future disble code. Nov 17, 2016 at 14:03
1

Since the page is already loaded $(".datepicker").datepicker("refresh"); will not reflect the changes.

Better if you could create a function which can used whenever required

function InitializeDate() {
    $(".datepicker").datepicker();
}
2
  • i tried your suggestion but not working, Inside resetManageRequest() function i am refreshing the datepicker but not working , look here my code -$('#txtdatereceiving').datepicker('refresh'); $('#txtTATdate').datepicker('refresh'); Nov 15, 2016 at 11:23
  • set async:false inside your $.ajax @Sudhakarsingh
    – Jays
    Nov 15, 2016 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.