89816

My jquery selectors doesn't work after update panel in content page

Question:

i have a content page, i write some jquery selectors after asp:updatepanel, for first time, when page loaded $(document).ready(function() works right, but after a postback, selectors doesnt work anymore, any way does exist to solve this problem??

<asp:content id="Content1" contentplaceholderid="contentplaceholder1" runat="server"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="txtdate" runat="server" CssClass="persianDTP" ></asp:TextBox> <!-- some code --> </ContentTemplate> </asp:UpdatePanel> <script> $(document).ready(function () { $('.PersianDTP').datepicker({ showOn: 'button', buttonImage: 'calendar.png', dateFormat: 'yy/mm/dd', //appendText: ' (yy/mm/dd)', changeMonth: true, changeYear: true, //selectOtherMonths: true, //showOtherMonths: true, showStatus: true, showButtonPanel: true, buttonImageOnly: true, buttonText: 'Choose a Date', onClose: function () { this.focus(); } }); jQuery(function ($) { $(".PersianDTP").mask("9999/99/99"); }); }); </script> </asp:content>

Answer1:

All JQuery plugins are applied on the Page Load event of the HTML Page or in other words document ready event which is fired when the whole page or document is rendered completely in browser .But when control is inside UpdatePanel and a Partial PostBack occurs the Unique Ids assigned by jQuery is lost and hence the plugin stops working , you could re-apply the jQuery Plugin every time the UpdatePanel’s Asynchronous request or Partial PostBack is completed : You need to recreate the Jquery Codes on postbacks. <br />sample code :)

<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script type="text/javascript"> $(document).ready(function () { $(<%=lstBoxTest.ClientID%>).SumoSelect({ selectAll: true }); }); Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); function EndRequestHandler(sender, args) { //Binding Code Again $(<%=lstBoxTest.ClientID%>).SumoSelect({ selectAll: true }); } </script>

Recommend

  • Modelstate always throws invalid datetime error
  • Spotfire Current Date in input field with calendar popup
  • How to find out what caused error crash report on IOS device?
  • Control event not firing from within updatepanel
  • got anyway i set class inside repeater datarow find by data ID when do postback?
  • Change button text in asp:gridview based on cell value C#
  • My jquery selectors doesn't work after update panel in content page
  • Is this concept of a button containing a textbox possible?
  • UserControl causes full postback in UpdatePanel
  • dynamically deleting tab panel in tab container in asp.net using vb.net
  • jQuery datepicker displaying a Buddhist date
  • WPF USer Control viewmodel binding
  • How to check when the table is inserted a new row and then auto update Repeater using UpdatePane
  • ASP.NET Ajax UpdatePanel flicker
  • WPF MVVM Binding a ContentConrol's ContentTemplate's StaticResource
  • Excluding dates in the jQuery datepicker using beforeShowDay and an array of objects
  • Asp.net updatepanel Listbox not refreshing layout
  • UpdatePanel does not prevent button from reload page
  • Matching IDs in Update Panel within a Repeater - “already contains a definition for…”
  • How do I preserve a value entered in a TextBox inside a gridview's templatefield when the gridv
  • WPF Binding View as Content
  • BundleConfig not rendered after publish in IIS
  • Using JQuery Datepicker To Only Show Months
  • A simple datepicker in VueJS
  • doPostBack from C# with JavaScript
  • How to link 2 Jquery UI datepickers with Knockout?
  • jQuery timepicker 'Object does not support this property or method'
  • How to install a .deb file on a jailbroken iphone programmatically?
  • DomPDF {PAGE_NUM} not on first page
  • Javascript simulate pressing enter in input box
  • Importing jscolor library in angular 2
  • jquery mobile loadPage not working
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • A cron job substitute?
  • Benchmarking RAM performance - UWP and C#
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal