DatePicker disappears after postback

11,514

Use pageLoad, it fires on partial postbacks:

   function pageLoad() { 
      $("#EditFromDate").datepicker({ ... });

   } 

$(document).ready() and pageLoad() are not the same!

Share:
11,514

Related videos on Youtube

Gonzalo
Author by

Gonzalo

Updated on July 16, 2022

Comments

  • Gonzalo
    Gonzalo almost 2 years

    I have an asp:TextBox associated to a jquery DatePicker. This input has a onTextChangedEvent that updates a Literal Control.

    All this code is inside an UpdatePanel so the Literal Control changes but the page doesn't refresh.

    The problem I'm facing is that when the event fires, the image that displays the DatePicker disappears. Here's a piece of my code:

    <asp:UpdatePanel ID="UpdatePanel" runat="server">
        <ContentTemplate>
    
            <asp:TextBox runat="server" OnTextChanged="EditFromDate_TextChanged"
            AutoPostBack="true"></asp:TextBox>
    
        </ContentTemplate>
     </asp:UpdatePanel>
    

    Then I have:

    $(document).ready(function()
    {
        $("#EditFromDate").datepicker({ ... });
    });
    

    Should I put the code that initiates the DatePicker elsewhere? I've tried placing it in Page Load using Page.RegisterStartup but same result.

    Thanks!

  • Gonzalo
    Gonzalo over 12 years
    Thanks!! So, when does $(document).ready() fire? And why putting this code in Page_Load event didn't work?
  • rick schott
    rick schott over 12 years
    Check out the article. If you put document.ready code in RegisterStartupScript on postback it will work as well.
  • Ryan Leach
    Ryan Leach over 2 years
    And now the link links to shady pdf sites.