Page view counter

jQuery methods and UpdatePanel

Last post 02-01-2009 1:55 PM by gt1329a. 5 replies.

Sort Posts:

  • jQuery methods and UpdatePanel

    12-03-2007, 6:02 PM
    • Loading...
    • rdelgadoj
    • Joined on 08-01-2007, 6:12 PM
    • Costa Rica
    • Posts 5
    • Points 9

    Hello,

     I'm using  jQuery to show and hide a div in my page... I wrote this in codeinline:

     

    <script type="text/javascript" src="Scripts/jquery.js"></script>

    <script type="text/javascript">

    $(document).ready(

    function() {

    $('#remindershide').hide();

    $('#slick-slidetoggle').click(

    function() {

    $('#remindershide').slideToggle(400);return false;

    });

    $('#cancelReminder').click(

    function() {

    $('#remindershide').slideToggle(400);

    return false;

    });

    });

    </script>

     

    Everything is ok so far, I had to put a Timer and update some data from condebehind, the problem is that, after every update my slick-slidetoggle div loose all the java functionality... what am I doing wrong???

     

    Thanks

     

     

     

  • Re: jQuery methods and UpdatePanel

    12-03-2007, 7:30 PM
    Answer
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,054
    • Points 12,285
    • ASPInsiders

    What's happening is your UpdatePanel refreshes are reverting the DOM back to how it was before jQuery wired up those handlers.  The quick and dirty fix is to move that jQuery code into pageLoad() instead of $(document).ready(), since pageLoad fires after every partial postback.

    Encosia - ASP.NET, AJAX, and more.

    Latest article: Never worry about ASP.NET AJAX's .d again
  • Re: jQuery methods and UpdatePanel

    02-01-2009, 10:04 AM
    • Loading...
    • the-pixel
    • Joined on 02-01-2009, 3:00 PM
    • Posts 2
    • Points 4
    Hi! I've had the same issue using jquery slidetoggle. I moved the event binding to the pageLoad() method. But now, every time I'm doing an UpdatePanel Update, and click on my slideToggle button, the div collapses and expands several times, depending how often I did an update in an updatepanel... any suggestions?
  • Re: jQuery methods and UpdatePanel

    02-01-2009, 1:28 PM
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,054
    • Points 12,285
    • ASPInsiders

    You have to be careful when wiring up events in pageLoad(), whether using jQuery or ASP.NET AJAX's $addHandler, because it's possible to wire up multiple copies of the same event to the same element.  In the previous poster's case of a Timer that updates everything, pageLoad() is the easiest way and is safe since the elements will be replaced after every Timer tick.

    If you're using jQuery 1.3.x, the easiest way to resolve your problem is to use the new "live" functionality.  That's extremely useful when using jQuery with UpdatePanels.

    Encosia - ASP.NET, AJAX, and more.

    Latest article: Never worry about ASP.NET AJAX's .d again
  • Re: jQuery methods and UpdatePanel

    02-01-2009, 1:50 PM
    • Loading...
    • the-pixel
    • Joined on 02-01-2009, 3:00 PM
    • Posts 2
    • Points 4
    Because of some bugs in the new release I cant use 1.3.x and have to stick to 1.2.6... so is there maybe a way to unwire events from elements. I already searched for a solution for this issue, but it seems no one uses the combination of jquery, updatepanels and slidetoggle.
  • Re: jQuery methods and UpdatePanel

    02-01-2009, 1:55 PM
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,054
    • Points 12,285
    • ASPInsiders

    You can use unbind().  Just place a call to that before your event handler wireup in pageLoad().

    function pageLoad() {
      $('element').unbind();
      $('element').click(function() { alert('click'); });
    }
     
    Encosia - ASP.NET, AJAX, and more.

    Latest article: Never worry about ASP.NET AJAX's .d again
Page 1 of 1 (6 items)