Saturday, July 18, 2020

Solution: Datepicker not working within updatepanel

Leave a Comment
Problem Statement:

Got chance to work on an existing project where in webform within update panel bootstrap datepicker control isn't working after callback/postback.

Solution:

Bind & Update datepicker controls at endRequest as follows:
$(function () {
   bindDatePickers(); // bind date picker on first page load
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindDatePickers); // bind date picker on every UpdatePanel refresh
});

function bindDatePickers() {
   $('#<%= txtStartDateFrom.ClientID%>').datepicker({
      uiLibrary: 'bootstrap4'
   });
   $('#<%= txtEndDateTo.ClientID%>').datepicker({
      uiLibrary: 'bootstrap4'
   });
 }
If You Enjoyed This, Take 5 Seconds To Share It

0 comments: