jquery datepicker ms ajax updatepanel doesn't work after post back jquery datepicker ms ajax updatepanel doesn't work after post back jquery jquery

jquery datepicker ms ajax updatepanel doesn't work after post back


the update panel is going to reload the contents of the html. You'll have to listen for the UpdatePanel to complete and recreate the datepicker.

Here is a very basic sample. This doesn't take into account multiple update panels on your page or potential memory leaks from not properly destroying your datepicker.

Another thing to note when mixing ASP.NET Ajax and jQuery be careful because the both use the $ in different contexts

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.js">    </script>    <script type="text/javascript">        $(document).ready(function() {            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);            function EndRequestHandler(sender, args) {                $('.mydatepickerclass').datepicker({ dateFormat: 'dd-mm-yy' });            }        });    </script>   </head><body>    <form id="form1" runat="server">    <div>    </div>    <asp:ScriptManager ID="ScriptManager1" runat="server">    </asp:ScriptManager>    <asp:UpdatePanel ID="UpdatePanel1" runat="server">        <ContentTemplate>            <asp:TextBox ID="TextBox1" runat="server" CssClass="mydatepickerclass"></asp:TextBox>            <br />            <asp:Button ID="Button1" runat="server" Text="UpdateMe"                 onclick="Button1_Click" />        </ContentTemplate>    </asp:UpdatePanel>    </form></body></html>


I know this is old but ... try replace:

$(document).ready(function() {

with:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function () {


Instead of doing this there is a simple alternative.

In the postback of the element in update panel add this code

ScriptManager.RegisterStartupScript(Me, Me.GetType(), "asddas", "getjquerydate();",   True)

And this in javascript

function getjquerydate() {$(".datepicker").datepicker({    numberOfMonths: 2,    showButtonPanel: true,    minDate: 1,    dateFormat: 'dd/mm/yy',    showOn: "button",    buttonImage: "images/calendar.gif",    buttonImageOnly: true});

}

After Partial postback in updated panel it again call the datepicker function