<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Married Geek » ASP.NET, jQuery, Web, JavaScript, and CSS blog &#187; jquery</title>
	<atom:link href="http://marriedgeek.com/index.php/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://marriedgeek.com</link>
	<description></description>
	<lastBuildDate>Thu, 14 Apr 2011 15:58:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Add some jQuery animation to UpdatePanel postbacks</title>
		<link>http://marriedgeek.com/2009/07/jquery-animation-updatepanel/</link>
		<comments>http://marriedgeek.com/2009/07/jquery-animation-updatepanel/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 05:05:41 +0000</pubDate>
		<dc:creator>_theMarriedGeek</dc:creator>
				<category><![CDATA[ASP.NET and Web]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[updatepanel]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.marriedgeek.com/?p=110</guid>
		<description><![CDATA[Here&#8217;s a little eye-candy trick if you&#8217;re one of those using UpdatePanel Â in ASP.NET (and not caring about performance, ahem) that will allow for a quick animation (e.g., fade, slide) on any data getting refreshed from the server. The method uses jQuery to handle the animation and a few lines of JavaScript to inject the [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little eye-candy trick if you&#8217;re one of those using UpdatePanel Â in ASP.NET (and not caring about performance, ahem) that will allow for a quick animation (e.g., fade, slide) on any data getting refreshed from the server. The method uses jQuery to handle the animation and a few lines of JavaScript to inject the animation into the &#8220;click&#8221; event of a button (or any other element!).</p>
<p>A neat use of this would be for, say, a GridView of data. You may have a series of filters for that data and instead of having that data (asynchronously) refresh with little notice from the user, you add a slideIn()/slideOut() animation so that the user can visually see exactly what is being refreshed.</p>
<p>The process involves <strong>1)</strong> grabbing whatever the current onclick handler is for each element, <strong>2)</strong> initializing the new &#8220;click&#8221; handlers for the buttons incorporating the new fadeOut or slideUp effect, and <strong>3)</strong> binding your final effect for when the AJAX response is received.</p>
<p>The following code will invoke a function, <strong>InitBrowseButtons()</strong>, when the DOM is ready when the page is initially loaded (if your buttons invoking the &#8220;asynchronicity&#8221; are inside the update panel, you&#8217;ll need to do run ScriptManager.RegisterStartupScript(&#8230;) to re-bind the handlers). For this code, I bound a checkbox control that updates the data in the UpdatePanel when checked or unchecked. This can easily be substituted for a button or other element by changing the jQuery selector.</p>
<pre>$(document).ready(function()
{
    InitBrowseButtons();
});

// round up the elements using jQuery selectors, grab the current onclick and insert your own
function InitBrowseButtons()
{
    $("input[type='checkbox'][name$='chkBrowseAll']").each(function()
    {
        var currAction = $(this).attr("onclick");

        $(this).attr("onclick", "").click(function()
        {
            $("div[id$='upMessages']").slideUp(500, function() { currAction(); });
        });
    });
}</pre>
<p>This function will cycle through all the elements grabbed by the selector (only one in this case) and, for each, save the current onclick handler to a variable. It will then reassign a click event to that element, in thise case, a jQuery animation to slideUp an UpdatePanel named upMessages. On the callback event for the animation, it will then invoke the previous click handler (the parenthesis will invoke the variable as a function).</p>
<p>This function will handle the slideUp and the subsequent postback event, but what about when the data is posted back? The following function is invoked by static method ScriptManager.RegisterStartupScript(&#8230;) from the code-behind file. This will invoke a script each time a postback is complete.</p>
<p>The C# script (I called it from Page_Load, but adjust as necessary)&#8230;</p>
<pre>ScriptManager.RegisterStartupScript(Page, Page.GetType(), "InitFadeData", "InitFadeData();", true);</pre>
<p>&#8230; will invoke the following JavaScript&#8230;</p>
<pre>// function called when post back is completed
function InitFadeData()
{
    $("div[id$='upMessages']").slideDown(500);
}</pre>
<p>This script grabs the same UpdatePanel (which is just a DIV) and slides the content open once it is repopulated with server-side data.</p>
<p><strong>A demo can be found <a href="http://sandbox.marriedgeek.com/slide.aspx" target="_blank">here</a>. Source code <a href="http://sandbox.marriedgeek.com/slide.zip">here</a>. </strong>All scripts were inline for the purposes of viewing.</p>
<p><em>And just to note about the performance of UpdatePanels; yes, they&#8217;re great for quick-and-dirty partial updates, but should mainly be used for low traffic sites or for administratitive sites (CMSes and other private web sites). Otherwise, use the built-in page methods or use jQuery&#8217;s AJAX methods and render your own UIs. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://marriedgeek.com/2009/07/jquery-animation-updatepanel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
