<p>I have just started working with the <code>AnimationExtender</code>.  I am using it to show a new div with a list gathered from a database when a button is pressed.  The problem is the button needs to do a postback to get this list as I don't want to make the call to the database unless it's needed.  The postback however stops the animation mid flow and resets it.  The button is within an update panel.</p>

<p>Ideally I would want the animation to start once the postback is complete and the list has been gathered.  I have looked into using the <code>ScriptManager</code> to detect when the postback is complete and have made some progress.  I have added two javascript methods to the page.</p>

<pre><code>function linkPostback() {

        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(playAnimation)
    }

    function playAnimation() {
        var onclkBehavior = $find("ctl00_btnOpenList").get_OnClickBehavior().get_animation();
        onclkBehavior.play();
    }
</code></pre>

<p>And I’ve changed the <code>btnOpenList.OnClientClick=”linkPostback();”</code></p>

<p>This almost solves the problem.  I’m still get some animation stutter.  The animation starts to play before the postback and then plays properly after postback.  Using the <code>onclkBehavior.pause()</code> has no effect.  I can get around this by setting the <code>AnimationExtender.Enabled = false</code> and setting it to true in the buttons postback event.  This however works only once as now the AnimationExtender is enabled again.  I have also tried disabling the <code>AnimationExtender</code> via javascript but this has no effect.</p>

<p>Is there a way of playing the animations only via javascript calls?  I need to decouple the automatic link to the 
buttons click event so I can control when the animation is fired.</p>

<p>Hope that makes sense.</p>

<p>Thanks</p>

<p>DG</p>

[{'answer_id': 57774, 'author': 'Andrew Johnson', 'author_id': 5109, 'author_profile': 'https://Stackoverflow.com/users/5109', 'pm_score': 2, 'selected': True, 'text': '<p>The flow you are seeing is something like this:</p>\n\n<ol>\n<li>Click on button</li>\n<li>AnimationExtender catches action and call clickOn callback</li>\n<li>linkPostback starts asynchronous request for page and then returns flow to AnimationExtender</li>\n<li>Animation begins</li>\n<li>pageRequest returns and calls playAnimation, which starts the animation again</li>\n</ol>\n\n<p>I think there are at least two ways around this issue.  It seems you have almost all the javascript you need, you just need to work around AnimationExtender starting the animation on a click.</p>\n\n<p>Option 1: Hide the AnimationExtender button and add a new button of your own that plays the animation.  This should be as simple as setting the AE button\'s style to "display: none;" and having your own button call linkPostback().</p>\n\n<p>Option 2: Re-disable the Animation Extender once the animation has finished with.  This should work, as long as the playAnimation call is blocking, which it probably is:</p>\n\n<pre><code>function linkPostback() {\n\n    var prm = Sys.WebForms.PageRequestManager.getInstance();\n    prm.add_endRequest(playAnimation)\n}\n\nfunction playAnimation() {\n\n    AnimationExtender.Enabled = true;\n    var onclkBehavior = $find("ctl00_btnOpenList").get_OnClickBehavior().get_animation();\n    onclkBehavior.play();\n    AnimationExtender.Enabled = false;\n}\n</code></pre>\n\n<p>As an aside, it seems your general approach may face issues if there is a delay in receiving the pageRequest.  It may be a bit weird to click a button and several seconds later have the animation happen.  It may be better to either pre-load the data, or to pre-fill the div with some "Loading..." thing, make it about the right size, and then populate the actual contents when it arrives.</p>\n'}, {'answer_id': 84844, 'author': 'Magpie', 'author_id': 5170, 'author_profile': 'https://Stackoverflow.com/users/5170', 'pm_score': 0, 'selected': False, 'text': '<p>With help from the answer given the final solution was as follows:</p>\n\n<p>Add another button and hide it.</p>\n\n<pre><code>&lt;input id="btnHdn" runat="server" type="button" value="button" style="display:none;" /&gt;\n</code></pre>\n\n<p>Point the AnimationExtender to the hidden button so the firing of the unwanted click event never happens.</p>\n\n<pre><code>&lt;cc1:AnimationExtender ID="aniExt" runat="server" TargetControlID="btnHdn"&gt;\n</code></pre>\n\n<p>Wire the javascript to the button you want to trigger the animation after the postback is complete.</p>\n\n<pre><code>&lt;asp:ImageButton ID="btnShowList" runat="server" OnClick="btnShowList_Click" OnClientClick="linkPostback();" /&gt;\n</code></pre>\n\n<p>Add the required Javascript to the page.</p>\n\n<pre><code>function linkPostback() {\n        var prm = Sys.WebForms.PageRequestManager.getInstance();\n        prm.add_endRequest(playOpenAnimation)\n}\n\nfunction playOpenAnimation() {\n    var onclkBehavior = ind("ctl00_aniExt").get_OnClickBehavior().get_animation();\n    onclkBehavior.play();         \n\n    var prm = Sys.WebForms.PageRequestManager.getInstance();\n    prm.remove_endRequest(playOpenAnimation) \n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/49430', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5170/']