<?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>Think In Geek &#187; ajax</title>
	<atom:link href="http://thinkingeek.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkingeek.com</link>
	<description>In geek we trust</description>
	<lastBuildDate>Sat, 19 Jun 2010 22:00:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Disabling UpdatePanels when an asynchronous postback in progress</title>
		<link>http://thinkingeek.com/2009/06/08/disabling-updatepanels-when-an-asynchronous-postback-is-done/</link>
		<comments>http://thinkingeek.com/2009/06/08/disabling-updatepanels-when-an-asynchronous-postback-is-done/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 11:32:16 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=104</guid>
		<description><![CDATA[If you&#8217;ve ever worked with relatively large UpdatePanels maybe you&#8217;ll have had a problem: blocking the user some elements while the asynchronous postback is running. When working with local or LAN environments, the async responses might be fast, but over the internet, or on large calculations the async postback may take a while. During this [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever worked with relatively large UpdatePanels maybe you&#8217;ll have had a problem: blocking the user some elements while the asynchronous postback is running. When working with local or LAN environments, the async responses might be fast, but over the internet, or on large calculations the async postback may take a while. During this period, you may want to block the UpdatePanel controls so the user can&#8217;t trigger another postback or do any other operations on that UpdatePanel. I&#8217;ll show you an easy way to do so by using the AJAX framework for .NET and <a href="http://jquery.com" onclick="pageTracker._trackPageview('/outgoing/jquery.com?referer=');">jQuery</a> and one of its plugins: <a href="http://malsup.com/jquery/block/" onclick="pageTracker._trackPageview('/outgoing/malsup.com/jquery/block/?referer=');">blockUI</a>.</p>
<p>For those who don&#8217;t know jQuery, it&#8217;s an opensource Javascript framework that <a href="http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx" onclick="pageTracker._trackPageview('/outgoing/weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx?referer=');">is going to be embedded on future versions of Visual Studio</a>. It&#8217;s a very good framework because of its simplicity and its extensibility, having lots of plugins. One of those plugins is the blockUI plugin, which allows you to block and unlock any part of the DOM at will.</p>
<p><span id="more-104"></span></p>
<p>Let&#8217;s try this with a simple example. Imagine you have an UpdatePanel with various buttons, and you want that when a user clicks on any of it, all the interactive controls of the UpdatePanel become disabled until the asynchronous response has come back and the html has been updated. To do this, we need to know when the UpdatePanel is being updated. The best way to do this is to listen to an event of the <a href="http://msdn.microsoft.com/en-us/library/bb311028.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/bb311028.aspx?referer=');">PageRequestManager</a> object of our web page. The event is called <em>beginRequest</em> and the way we can attach to it is as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Sys.<span style="color: #660066;">WebForms</span>.<span style="color: #660066;">PageRequestManager</span>.<span style="color: #660066;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">add_beginRequest</span><span style="color: #009900;">&#40;</span>BeginRequestHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will get the instance of the PageRequestManager object and add a listener to the event, pointed at the javascript function called <em>BeginRequestHandler</em>.</p>
<p>The next step is to actually write this function. One option here would be to manually disable all the controls inside the UpdatePanel that can trigger a postback, but that would be very tedious. Instead, I propose you a way to directly disable all the UpdatePanel. We can do so by using the blockUI plugin from jQuery.<br />
The method will look like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> BeginRequestHandler<span style="color: #009900;">&#40;</span>sender<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">block</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This might need a bit of explanation. In jQuery, when using <em>$(&#8216;#element&#8217;)</em> we select the element of the DOM that has the id <em>&#8216;element&#8217;</em>. This returns a jQuery object upon which we can execute a series of commands (more on jQuery selectors on the jQuery website). Of those operations we can perform, there&#8217;s one that is provided with the blockUI plugin, and it&#8217;s called <em>block()</em>. This operation will simply block the DOM element that the jQuery selector has selected. With this simple line of code, then, we can disable an entire UpdatePanel. Since the UpdatePanel will be redrawn when the asynchronous postback comes back, it will be redrawn enabled again, so we don&#8217;t have to worry about enabling it again. </em></p>
<p><em>I suggest you visit the documentation of the blockUI plugin for more information and blocking options. In this example we simply disable the controls, but using some nice CSS you could use messages and html elements to notice the user that something is going to happen, like a nice <em>Loading</em> meassage or something similar.</p>
<p>Note that this will only work if you have only one UpdatePanel on the web page and all the controls that cause an asynchronous postback are inside the UpdatePanel. However, playing with the <em>sender</em> and <em>args</em> parameters of the <em>BeginRequestHandler</em> method, you can add some logic to decide which controls and UpdatePanels to block. I recommend visiting the <a href="http://msdn.microsoft.com/en-us/library/bb311028.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/bb311028.aspx?referer=');">PageRequestManager</a> page documentation for more information.</p>
<p>Finally, here&#8217;s a fully working example of a very simple web page. Notice that you&#8217;ll have to download <em>jquery.js</em> and <em>jquery.blockUI.js</em> from both websites I mentioned earlier.</p>
<p>Default.aspx.</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;">&nbsp;
    <span style="color: #006600; font-weight: bold;">&lt;</span>script src<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;jquery.js&quot;</span> type<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;text/javascript&quot;</span><span style="color: #006600; font-weight: bold;">&gt;&lt;!</span>--mce<span style="color: #006600; font-weight: bold;">:</span><span style="color: #800000;">0</span>--<span style="color: #006600; font-weight: bold;">&gt;&lt;/</span>script<span style="color: #006600; font-weight: bold;">&gt;</span>
    <span style="color: #006600; font-weight: bold;">&lt;</span>script src<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;jquery.blockUI.js&quot;</span> type<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;text/javascript&quot;</span><span style="color: #006600; font-weight: bold;">&gt;&lt;!</span>--mce<span style="color: #006600; font-weight: bold;">:</span><span style="color: #800000;">1</span>--<span style="color: #006600; font-weight: bold;">&gt;&lt;/</span>script<span style="color: #006600; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #006600; font-weight: bold;">&lt;</span>form id<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;form1&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span>
<span style="color: #006600; font-weight: bold;">&lt;</span>div<span style="color: #006600; font-weight: bold;">&gt;</span>
&nbsp;
    <span style="color: #006600; font-weight: bold;">&lt;</span>script type<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;text/javascript&quot;</span><span style="color: #006600; font-weight: bold;">&gt;&lt;!</span>--mce<span style="color: #006600; font-weight: bold;">:</span><span style="color: #800000;">2</span>--<span style="color: #006600; font-weight: bold;">&gt;&lt;/</span>script<span style="color: #006600; font-weight: bold;">&gt;&lt;/</span>div<span style="color: #006600; font-weight: bold;">&gt;</span>
<span style="color: #006600; font-weight: bold;">&lt;/</span>form<span style="color: #006600; font-weight: bold;">&gt;</span></pre></div></div>

<p>Default.aspx.cs.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> UpdatePanelBlockExample
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> _Default <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span></span>.<span style="color: #0000FF;">Page</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3000</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Label1.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>.<span style="color: #0000FF;">ToLongDateString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Button1_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3000</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Label1.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>.<span style="color: #0000FF;">ToShortDateString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p></em></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fthinkingeek.com%2F2009%2F06%2F08%2Fdisabling-updatepanels-when-an-asynchronous-postback-is-done%2F&amp;linkname=Disabling%20UpdatePanels%20when%20an%20asynchronous%20postback%20in%20progress" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fthinkingeek.com_2F2009_2F06_2F08_2Fdisabling-updatepanels-when-an-asynchronous-postback-is-done_2F_amp_linkname=Disabling_20UpdatePanels_20when_20an_20asynchronous_20postback_20in_20progress&amp;referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2009/06/08/disabling-updatepanels-when-an-asynchronous-postback-is-done/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Developing Javascript involved web applications with Firebug</title>
		<link>http://thinkingeek.com/2007/06/23/developing-javascript-involved-web-applications-with-firebug/</link>
		<comments>http://thinkingeek.com/2007/06/23/developing-javascript-involved-web-applications-with-firebug/#comments</comments>
		<pubDate>Sat, 23 Jun 2007 14:02:47 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=46</guid>
		<description><![CDATA[If you&#8217;ve been assigned to a new web application project lately, you&#8217;ll probably have had to deal with this [not] new AJAX technology. To be honest, AJAX is good, and websites like Google Mail and Flickr are good examples of that. But remember something: it&#8217;s always bad to abuse of something. It&#8217;s always bad to [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been assigned to a new web application project lately, you&#8217;ll probably have had to deal with this [not] new <a href="http://en.wikipedia.org/wiki/AJAX" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/AJAX?referer=');">AJAX</a> technology. To be honest, AJAX is good, and websites like <a href="http://mail.google.com/" onclick="pageTracker._trackPageview('/outgoing/mail.google.com/?referer=');">Google Mail</a> and <a href="http://www.flickr.com" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com?referer=');">Flickr</a> are good examples of that. But remember something: it&#8217;s always bad to abuse of something. It&#8217;s always bad to abuse AJAX. Don&#8217;t use it if it doesn&#8217;t really make sense to do it, and if your boss insists on it, ask him if he would use truck wheels on his BMW.</p>
<p><span id="more-46"></span></p>
<p>And using AJAX means Javascript, which is an interpreted, weakly typed programming language ran by the browser where the web page containing it executes. And believe me, Javascript is not easy. It&#8217;s not similar to Java, it&#8217;s not similar to C++ and it&#8217;s not similar to C#. To learn the tricks and tips of Javascript I recommend you start by reading this article from the MSDN: <a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=en" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx?loc=en&amp;referer=');">Create Advanced Web Applications With Object-Oriented Techniques</a>. It&#8217;s a very good introduction for people used to program with more typical object oriented programming languages.</p>
<p>And on top of that, Javascript is not easy to debug either, because you don&#8217;t have a compiler to test your code correctness (and I am not talking about syntax, for that you can use a specific editor like <a href="http://aptana.org/" onclick="pageTracker._trackPageview('/outgoing/aptana.org/?referer=');">Aptana</a> or any other free Javascript parser like <a href="http://www.jslint.com/" onclick="pageTracker._trackPageview('/outgoing/www.jslint.com/?referer=');">JSLint</a>), and because power is always dangerous, and Javascript is a very powerful tool which allows you to do some really dangerous things that can overcome you if not used wisely. Also, the fact that the client actually executing Javascript code is the browser makes things tricky, because you need to have some help from those programs to actually be able to access the execution of that code. Both <a href="http://www.microsoft.com/" onclick="pageTracker._trackPageview('/outgoing/www.microsoft.com/?referer=');">Microsoft</a> and <a href="http://www.getfirefox.com/" onclick="pageTracker._trackPageview('/outgoing/www.getfirefox.com/?referer=');">Firefox</a> have those tools. Unfortunately, the Microsoft ones are either crappy (like Microsoft Script Editor) or you have to pay a lot of money for them (either third party applications or Visual Studio). Fortunately, once more the Open Source community comes to our rescue. It&#8217;s name: <a href="http://www.getfirebug.com/" onclick="pageTracker._trackPageview('/outgoing/www.getfirebug.com/?referer=');">Firebug</a>.</p>
<p>Actually Firebug is much more than just a Javascript Debugger, it&#8217;s more like a mini web development suite for Firefox. It allows you to view and edit HTML and CSS in a fancy way and on the fly, you can naviagate through the DOM model of the web page in a fancy and easy way, it has a network monitoring feature to see how much bandwith is used on the web navigation and on the asynchonous callbacks, and most importantly, it has a Javascript debugger and profiler which has most of the features you might expect from another programming language debugger: inspects, flow control, breakpoints and so on. It has also a console which will tell you the errors encountered on your code and will point you exactly to the file and line of code that produced it. In a few words: it makes web and Javascript development a lot easier than it was before.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fthinkingeek.com%2F2007%2F06%2F23%2Fdeveloping-javascript-involved-web-applications-with-firebug%2F&amp;linkname=Developing%20Javascript%20involved%20web%20applications%20with%20Firebug" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fthinkingeek.com_2F2007_2F06_2F23_2Fdeveloping-javascript-involved-web-applications-with-firebug_2F_amp_linkname=Developing_20Javascript_20involved_20web_20applications_20with_20Firebug&amp;referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2007/06/23/developing-javascript-involved-web-applications-with-firebug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
