<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Disturbed Buddha</title>
	<atom:link href="http://disturbedbuddha.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://disturbedbuddha.wordpress.com</link>
	<description>Simple Thoughts from a Self-Proclaimed Novice</description>
	<pubDate>Thu, 31 Jan 2008 22:18:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>Highlighting a GridView Row When Clicking a CheckBox</title>
		<link>http://disturbedbuddha.wordpress.com/2008/01/31/highlighting-a-gridview-row-when-clicking-a-checkbox/</link>
		<comments>http://disturbedbuddha.wordpress.com/2008/01/31/highlighting-a-gridview-row-when-clicking-a-checkbox/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 22:17:09 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/?p=24</guid>
		<description><![CDATA[You&#8217;ve seen it in Yahoo!® Mail and numerous other places.  When you click a CheckBox next to an item, that item&#8217;s row changes color.  When you uncheck the box, the row returns to its original color.
&#160;



&#160;
Basically, we just need to attach a bit of JavaScript to handle the click event of each CheckBox in the GridView.  Here [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="margin:0;" class="MsoNormal">You&#8217;ve seen it in Yahoo!® Mail and numerous other places.  When you click a CheckBox next to an item, that item&#8217;s row changes color.  When you uncheck the box, the row returns to its original color.</p>
<p style="margin:0;" class="MsoNormal">&nbsp;</p>
<div style="text-align:center;">
<p style="margin:0;" class="MsoNormal"><img src="http://disturbedbuddha.files.wordpress.com/2008/01/highlightinggridviewrow.png" alt="Highlighting GridView Rows" /></p>
</div>
<p style="margin:0;" class="MsoNormal">&nbsp;</p>
<p style="margin:0;" class="MsoNormal">Basically, we just need to attach a bit of JavaScript to handle the click event of each CheckBox in the GridView.  Here is the JavaScript, if you were to see it by itself:</p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">&lt;script type="text/javascript"&gt;
    if (this.checked) {
        document.getElementById('theRowID').style.backgroundColor='Blue';
    } else {
        document.getElementById('theRowID').style.backgroundColor='';
    }
&lt;/script&gt;</pre>
<p style="margin:0;" class="MsoNormal">Notice that we&#8217;re setting the background color to an empty string when the CheckBox is unchecked.  We do this because we only want to remove the extra styling that we added.  That way, if your GridView has alternating row styles, it will go back to its original color.</p>
<p style="margin:0;" class="MsoNormal">&nbsp;</p>
<p style="margin:0;" class="MsoNormal">We are going to attach this event handler during the RowDataBound event of the GridView.  First, we check to make sure that it is a DataRow that we&#8217;re dealing with and not a header or footer.  Then we build the JavaScript using a StringBuilder (which you should use any time that you&#8217;re doing string concatenation).  We get the row&#8217;s ID from the arguments that were passed into the RowDataBound method:  e.Row.ClientID</p>
<p style="margin:0;" class="MsoNormal">&nbsp;</p>
<p style="margin:0;" class="MsoNormal">We then just have to use the FindControl method on the current row and add the event and our JavaScript as an attribute to the CheckBox.  Simple as that!</p>
<p style="margin:0;" class="MsoNormal">&nbsp;</p>
<p style="margin:0;" class="MsoNormal"><strong>VB.NET:</strong></p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    If (e.Row.RowType = DataControlRowType.DataRow) Then
        Dim script As New StringBuilder
        script.Append("if (this.checked) {")
        script.Append("document.getElementById('")
        script.Append(e.Row.ClientID)
        script.Append("').style.backgroundColor='Blue';")
        script.Append("} else {")
        script.Append("document.getElementById('")
        script.Append(e.Row.ClientID)
        script.Append("').style.backgroundColor='';")
        script.Append("}")
        CType(e.Row.Cells(0).FindControl("CheckBox1"), CheckBox).Attributes.Add("onclick", script.ToString)
    End If
End Sub</pre>
<p style="margin:0;" class="MsoNormal">I&#8217;m sure that you can see how this code could easily be built upon to include fading in/fading out of the color or any other UI effect.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=24&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2008/01/31/highlighting-a-gridview-row-when-clicking-a-checkbox/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>

		<media:content url="http://disturbedbuddha.files.wordpress.com/2008/01/highlightinggridviewrow.png" medium="image">
			<media:title type="html">Highlighting GridView Rows</media:title>
		</media:content>
	</item>
		<item>
		<title>Determining a Browser&#8217;s Dimensions with Javascript</title>
		<link>http://disturbedbuddha.wordpress.com/2008/01/22/determining-a-browsers-dimensions-with-javascript/</link>
		<comments>http://disturbedbuddha.wordpress.com/2008/01/22/determining-a-browsers-dimensions-with-javascript/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 15:24:11 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2008/01/22/determining-a-browsers-dimensions-with-javascript/</guid>
		<description><![CDATA[This is about as cross-browswer compatible as you can get:
&#60;script type="text/javascript"&#62;
    var winW, winH;
    if (self.innerWidth) {
        winW = self.innerWidth;
        winH = self.innerHeight;
    } else if (document.documentElement &#38;&#38; document.documentElement.clientWidth) {
    [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This is about as cross-browswer compatible as you can get:</p>
<pre style="background-color:#cccccc;padding:2px;">&lt;script type="text/javascript"&gt;
    var winW, winH;
    if (self.innerWidth) {
        winW = self.innerWidth;
        winH = self.innerHeight;
    } else if (document.documentElement &amp;&amp; document.documentElement.clientWidth) {
        winW = document.documentElement.clientWidth;
        winH = document.documentElement.clientHeight;
    } else if (document.body) {
        winW = document.body.clientWidth;
        winH = document.body.clientHeight;
    }
&lt;/script&gt;</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=18&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2008/01/22/determining-a-browsers-dimensions-with-javascript/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
		<item>
		<title>Executing Server-side Code from JavaScript</title>
		<link>http://disturbedbuddha.wordpress.com/2008/01/08/executing-server-side-code-from-javascript/</link>
		<comments>http://disturbedbuddha.wordpress.com/2008/01/08/executing-server-side-code-from-javascript/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 19:37:45 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2008/01/08/executing-server-side-code-from-javascript/</guid>
		<description><![CDATA[In the Asp.net forums, I often see the question asked, “Can I call server-side code from the client/JavaScript?” Almost invariably, the responses given are “No, the client cannot access the server,” or “You can only use WebMethods or PageMethods.” The first response is not entirely correct, and unfortunately, WebMethods and PageMethods are static methods and [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In the <a target="_blank" href="http://forums.asp.net/">Asp.net forums</a>, I often see the question asked, “Can I call server-side code from the client/JavaScript?” Almost invariably, the responses given are “No, the client cannot access the server,” or “You can only use WebMethods or PageMethods.” The first response is not entirely correct, and unfortunately, WebMethods and PageMethods are static methods and therefore have no way to directly access the page.</p>
<p>This is why I present to you the following “hack”. I call it a hack because there really should be some way built into the ASP.NET AJAX Extensions that allow this approach directly. Instead, it relies on using controls in a manner that they aren’t necessarily intended in order to obtain the desired result. But this “hack” does have a redeeming quality—it’s incredibly easy.</p>
<p><strong>The Code:</strong></p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">&lt;%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %&gt;         

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
&lt;head runat="server"&gt;
  &lt;title&gt;My Page&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
    function myClientButton_onclick() {
    document.getElementById('myServerButton').click();
  }
  &lt;/script&gt;
  &lt;script runat="server"&gt;
    Protected Sub myServerButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles myServerButton.Click
      Response.Redirect("http://www.asp.net/")
    End Sub
  &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;form id="form1" runat="server"&gt;
    &lt;input id="myClientButton" type="button" value="Press Me" onclick="return myClientButton_onclick()" /&gt;
    &lt;asp:Button ID="myServerButton" runat="server" style="display:none;" /&gt;
  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>Explanation:</strong></p>
<p>What I am doing here is adding a server-side button control (<span style="font-family:Courier New, Courier;">&lt;asp:Button runat=”server” …&gt;</span>). I then make the button invisible by adding <span style="font-family:Courier New, Courier;">style=”display:none;”</span>. In the button’s server-side Click event, I do whatever it is I want to do on the server.</p>
<p>In this example, I am clicking a standard client-side button (<span style="font-family:Courier New, Courier;">&lt;input type=”button” …&gt;</span>) to fire off a server-side redirect, but this could just as easily be called by selecting an item in a DropDownList, typing text into a textbox, etc. Clicking the client button calls the <a target="_blank" href="http://www.w3schools.com/htmldom/met_button_click.asp">JavaScript <span style="font-family:Courier New, Courier;">.click()</span> event</a> of the server-side button control.</p>
<p><strong>The Next Step:</strong></p>
<p>“What if I need to pass arguments from the client-side script to the server-side script?” Well, this is easily done by putting server-side HiddenField controls on the page. Use the JavaScript to set their values (<span style="font-family:Courier New, Courier;">document.getElementById(‘myHiddenField’).value = “Hello World”;</span>) and then use C# or VB.NET to retrieve them on the server (<span style="font-family:Courier New, Courier;">Dim myVar as String = myHiddenField.Value</span>).</p>
<p>In my next article, I will apply this concept to create a rather easy approach to the Ajax Multi-Stage Download Pattern. Check back soon!</p>
<p>Tested on: Internet Explorer 7, Netscape Browser 8, Firefox 2, Safari 3, Opera 9.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=16&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2008/01/08/executing-server-side-code-from-javascript/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
		<item>
		<title>Wrapping ASP.NET AJAX TabContainer Tabs</title>
		<link>http://disturbedbuddha.wordpress.com/2007/12/19/wrapping-aspnet-ajax-tabcontainer-tabs/</link>
		<comments>http://disturbedbuddha.wordpress.com/2007/12/19/wrapping-aspnet-ajax-tabcontainer-tabs/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 18:37:37 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2007/12/19/wrapping-aspnet-ajax-tabcontainer-tabs/</guid>
		<description><![CDATA[Check out Nazar Rizvi&#8217;s article on how to get your tab headers to wrap onto a second row for your ASP.NET AJAX TabContainer control.  Common problem; easy fix.
http://www.narizvi.com/blog/post/Two-rows-of-tab-headers-in-TabContainer-in-Ajax-Control-Toolkit.aspx
       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Check out Nazar Rizvi&#8217;s article on how to get your tab headers to wrap onto a second row for your ASP.NET AJAX TabContainer control.  Common problem; easy fix.</p>
<p><a target="_new" href="http://www.narizvi.com/blog/post/Two-rows-of-tab-headers-in-TabContainer-in-Ajax-Control-Toolkit.aspx">http://www.narizvi.com/blog/post/Two-rows-of-tab-headers-in-TabContainer-in-Ajax-Control-Toolkit.aspx</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=15&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2007/12/19/wrapping-aspnet-ajax-tabcontainer-tabs/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
		<item>
		<title>Handling Multiple Asynchronous Postbacks</title>
		<link>http://disturbedbuddha.wordpress.com/2007/12/12/handling-multiple-asynchronous-postbacks/</link>
		<comments>http://disturbedbuddha.wordpress.com/2007/12/12/handling-multiple-asynchronous-postbacks/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 21:06:27 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2007/12/12/handling-multiple-asynchronous-postbacks/</guid>
		<description><![CDATA[Sometimes multiple asynchronous postbacks get triggered. Now, I’m not talking about situations where we want to disable a submit button, so that the user doesn’t click it fifty times waiting for something to happen. Instead, I’m referring to situations where we do want each postback to happen in the order it was fired.
However, when a [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Sometimes multiple asynchronous postbacks get triggered. Now, I’m not talking about situations where we want to disable a submit button, so that the user doesn’t click it fifty times waiting for something to happen. Instead, I’m referring to <em>situations where we do want each postback to happen in the order it was fired</em>.</p>
<p>However, when a page makes multiple asynchronous postbacks at the same time, the default action is that <u>the PageRequestManager gives the most recent postback precedence</u>. This cancels any prior asynchronous postback requests that have not yet been processed. (<a target="_blank" href="http://www.asp.net/ajax/documentation/live/tutorials/ExclusiveAsyncPostback.aspx" title="Giving Precedence to a Specific Asynchronous Postback">Get further explanation</a>.)</p>
<p>So, let’s create a way to <em>“queue up” our asynchronous postback requests and fire them off in order, one by one</em>. First, let’s create an aspx page with three buttons inside of an UpdatePanel:</p>
<pre style="background-color:#cccccc;padding:2px;">&lt;asp:ScriptManager ID="ScriptManager1" runat="server" /&gt;
&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
    &lt;ContentTemplate&gt;
        &lt;asp:Button ID="Button1" runat="server" Text="Button" /&gt;
        &lt;asp:Button ID="Button2" runat="server" Text="Button" /&gt;
        &lt;asp:Button ID="Button3" runat="server" Text="Button" /&gt;
    &lt;/ContentTemplate&gt;
&lt;/asp:UpdatePanel&gt;</pre>
<p>There is no need to wire up any click events in the code-behind for our sample. While you could, all that we are concerned about is that they each cause a postback.</p>
<p>Next, let’s add some deliberate latency into the code so that our postback requests can pile up. Every postback to the server will now take 3 ½ seconds, so that is the fastest each request can be processed.</p>
<pre style="background-color:#cccccc;padding:2px;">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  System.Threading.Thread.Sleep(3500)
End Sub</pre>
<p>Now, let’s look at the JavaScript code that will manage the backed-up postback requests for us. Add this script block <u>after the ScriptManager</u> on the page but before the closing &lt;/html&gt; tag.</p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">&lt;script type="text/javascript"&gt;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequestHandler);
    prm.add_endRequest(EndRequestHandler);        

    var pbQueue = new Array();
    var argsQueue = new Array();       

    function InitializeRequestHandler(sender, args) {
        if (prm.get_isInAsyncPostBack()) {
            args.set_cancel(true);
            pbQueue.push(args.get_postBackElement().id);
            argsQueue.push(document.forms[0].<font size="2">__EVENTARGUMENT.value);</font>
        }
    }       

    function EndRequestHandler(sender, args) {
        if (pbQueue.length &gt; 0) {
            __doPostBack(pbQueue.shift(), argsQueue.shift());
        }
    }
&lt;/script&gt;</pre>
<p><strong>The Code in Detail</strong></p>
<p>First, we use the PageRequestManager to set up handlers for the beginning and end of each asynchronous request:</p>
<pre style="background-color:#cccccc;padding:2px;">var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequestHandler);
prm.add_endRequest(EndRequestHandler);</pre>
<p><strong>Queuing up the Postbacks…</strong></p>
<p>Then we create an array to store the originator of each asynchronous postback that cannot be processed immediately, as well as an array to store any event arguments associated with the postback:</p>
<pre style="background-color:#cccccc;padding:2px;">var pbQueue = new Array();
var argsQueue = new Array();</pre>
<p>Then, at the beginning of each asynchronous postback, we check to see if the page is already in an asynchronous postback:</p>
<pre style="background-color:#cccccc;padding:2px;">function InitializeRequestHandler(sender, args) {
    if (prm.get_isInAsyncPostBack()) {...}</pre>
<p>If it is, we cancel the new postback request, and instead, add the event target and arguments to our arrays:</p>
<pre style="background-color:#cccccc;padding:2px;">args.set_cancel(true);
pbQueue.push(args.get_postBackElement().id);
argsQue.push(<font size="2">document.forms[0].__EVENTARGUMENT.value);</font></pre>
<p><strong>…and Executing Them</strong></p>
<p>After each asynchronous postback completes, we check to see if there are any more queued up, and if so, we do a __doPostBack(). pbQueue.shift() pulls the first item out of the array and removes it.</p>
<pre style="background-color:#cccccc;padding:2px;">function EndRequestHandler(sender, args) {
    if (pbQueue.length &gt; 0) {
        __doPostBack(pbQueue.shift(), argsQueue.shift());
    }
}</pre>
<p>And that’s it. Run the page, and randomly click some buttons! If you watch the browser’s status bar, you’ll see the asynchronous postbacks piling up. Then, every 3 ½ seconds, you’ll see one of them being processed! (Remember, the 3 ½ seconds is just an arbitrary time that we added into this demonstration, and it has nothing to do with how the code really works.)</p>
<p><strong>Note:</strong> If for some reason, you wanted to execute the asynchronous postbacks in reverse chronological order (i.e., the most recent requests get processed first), just replace the <em>array</em>.shift() command in the EndRequestHandler() with <em>array</em>.pop().</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=14&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2007/12/12/handling-multiple-asynchronous-postbacks/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
		<item>
		<title>Disabling a Trigger Control During Asynchronous PostBack</title>
		<link>http://disturbedbuddha.wordpress.com/2007/12/10/disabling-a-trigger-control-during-asynchronous-postback/</link>
		<comments>http://disturbedbuddha.wordpress.com/2007/12/10/disabling-a-trigger-control-during-asynchronous-postback/#comments</comments>
		<pubDate>Mon, 10 Dec 2007 16:52:40 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2007/12/10/disabling-a-trigger-control-during-asynchronous-postback/</guid>
		<description><![CDATA[Often, we want to disable the control that triggered an asynchronous postback until the postback has completed. This prohibites the user from triggering another postback until the current one is complete.
The Code
First add a ScriptManager to the page, immediately following the &#60;form&#62; tag.
&#60;asp:ScriptManager ID="ScriptManager1" runat="server" /&#62;
Then add a Label wrapped in an UpdatePanel. This label [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Often, we want to disable the control that triggered an asynchronous postback until the postback has completed. This prohibites the user from triggering another postback until the current one is complete.</p>
<p><strong>The Code</strong></p>
<p>First add a ScriptManager to the page, immediately following the &lt;form&gt; tag.</p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">&lt;asp:ScriptManager ID="ScriptManager1" runat="server" /&gt;</pre>
<p>Then add a Label wrapped in an UpdatePanel. This label will be populated with the date and time on each postback. We’ll also add a Button inside of the UpdatePanel to cause the postback.</p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
    &lt;ContentTemplate&gt;
        &lt;asp:Label ID="Label1" runat="server" Text="Label" /&gt;&lt;br /&gt;
        &lt;asp:Button ID="Button1" runat="server" Text="Update Time" OnClick="Button1_Click" /&gt;
    &lt;/ContentTemplate&gt;
&lt;/asp:UpdatePanel&gt;</pre>
<p>We’ll also add an UpdateProgress control and associate it with our UpdatePanel just to let the user know that something’s happening.</p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">&lt;asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"&gt;
    &lt;ProgressTemplate&gt;
        Loading...
    &lt;/ProgressTemplate&gt;
&lt;/asp:UpdateProgress&gt;</pre>
<p>Next, we’ll add a events in the code-behind to populate the Label and to introduce some latency, simulating a lengthy update to the page.</p>
<p><strong>VB.NET:</strong></p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Label1.Text = Now.ToString
End Sub</pre>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    System.Threading.Thread.Sleep(4000)  'Pause for 4 seconds.
End Sub</pre>
<p>And finally we’ll add the client-side code to disable our button during the postback. The Javascript disables the button during the <a target="_blank" href="http://asp.net/ajax/documentation/live/clientreference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerBeginRequestEvent.aspx">beginRequest</a> event of the <a target="_blank" href="http://asp.net/ajax/documentation/live/clientreference/Sys.WebForms/PageRequestManagerClass/default.aspx">PageRequestManager</a> and enables it when control has been returned to the browser in the <a target="_blank" href="http://asp.net/ajax/documentation/live/clientreference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerEndRequestEvent.aspx">endRequest</a> event. The control causing the postback is returned from the get_postBackElement() method of the <a target="_blank" href="http://asp.net/ajax/documentation/live/ClientReference/Sys.WebForms/BeginRequestEventArgsClass/default.aspx">BeginRequestEventArgs object</a> which is passed to the function handling the beginRequest event.</p>
<p>Add the follow script after the ScriptManager on the page:</p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">&lt;script type="text/javascript"&gt;
    var pbControl = null;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        pbControl = args.get_postBackElement();  //the control causing the postback
        pbControl.disabled = true;
    }
    function EndRequestHandler(sender, args) {
        pbControl.disabled = false;
        pbControl = null;
    }
&lt;/script&gt;</pre>
<p>And that&#8217;s it!</p>
<p><strong>The Complete Source Code:</strong></p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">&lt;%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %&gt;
&lt;%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
    &lt;head runat="server"&gt;
        &lt;title&gt;Untitled Page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;form id="form1" runat="server"&gt;
            &lt;asp:ScriptManager ID="ScriptManager1" runat="server" /&gt;
            &lt;script type="text/javascript"&gt;
                var pbControl = null;
                var prm = Sys.WebForms.PageRequestManager.getInstance();
                prm.add_beginRequest(BeginRequestHandler);
                prm.add_endRequest(EndRequestHandler);
                function BeginRequestHandler(sender, args) {
                    pbControl = args.get_postBackElement();  //the control causing the postback
                    pbControl.disabled = true;
                }
                function EndRequestHandler(sender, args) {
                    pbControl.disabled = false;
                    pbControl = null;
                }
            &lt;/script&gt;
            &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
                &lt;ContentTemplate&gt;
                    &lt;asp:Label ID="Label1" runat="server" Text="Label" /&gt;&lt;br /&gt;
                    &lt;asp:Button ID="Button1" runat="server" Text="Update Time" OnClick="Button1_Click" /&gt;
                &lt;/ContentTemplate&gt;
            &lt;/asp:UpdatePanel&gt;
            &lt;asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"&gt;
                &lt;ProgressTemplate&gt;
                    Loading...
                &lt;/ProgressTemplate&gt;
            &lt;/asp:UpdateProgress&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=13&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2007/12/10/disabling-a-trigger-control-during-asynchronous-postback/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
		<item>
		<title>Maintain Scroll Position after Asynchronous Postback</title>
		<link>http://disturbedbuddha.wordpress.com/2007/12/03/maintain-scroll-position-after-asynchronous-postback/</link>
		<comments>http://disturbedbuddha.wordpress.com/2007/12/03/maintain-scroll-position-after-asynchronous-postback/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 15:38:29 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2007/12/03/maintain-scroll-position-after-asynchronous-postback/</guid>
		<description><![CDATA[Do you want to maintain the scroll position of a GridView, Div, Panel, or whatever that is inside of an UpdatePanel after an asynchronous postback?  Normally, if the updatepanel posts back, the item will scroll back to the top because it has been reloaded.  What you need to do is &#8220;remember&#8221; where the item was scrolled to and [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Do you want to maintain the scroll position of a GridView, Div, Panel, or whatever that is inside of an UpdatePanel after an asynchronous postback?  Normally, if the updatepanel posts back, the item will scroll back to the top because it has been reloaded.  What you need to do is &#8220;remember&#8221; where the item was scrolled to and jump back to there after the postback.  Place the following script <u>after</u> the ScriptManager on your page.  And since the _endRequest event of the PageRequestManager happens before the page is rendered, you&#8217;ll never even see your item move!</p>
<pre style="overflow:scroll;font-family:'Courier New';background-color:#cccccc;padding:2px;">&lt;script type="text/javascript"&gt;
    var xPos, yPos;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        xPos = $get('scrollDiv').scrollLeft;
        yPos = $get('scrollDiv').scrollTop;
    }
    function EndRequestHandler(sender, args) {
        $get('scrollDiv').scrollLeft = xPos;
        $get('scrollDiv').scrollTop = yPos;
    }
&lt;/script&gt;</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=11&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2007/12/03/maintain-scroll-position-after-asynchronous-postback/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
		<item>
		<title>Selecting an AJAX AccordionPane by ID</title>
		<link>http://disturbedbuddha.wordpress.com/2007/11/30/selecting-an-ajax-accordionpane-by-id/</link>
		<comments>http://disturbedbuddha.wordpress.com/2007/11/30/selecting-an-ajax-accordionpane-by-id/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 16:05:22 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2007/11/30/selecting-an-ajax-accordionpane-by-id/</guid>
		<description><![CDATA[Typically, if we want to programmatically select a particular AccordionPane within an ASP.NET AJAX Accordion control, we set the SelectedIndex property.  This is great if we know the exact order of our AccordionPanes at all times, but this isn&#8217;t always so.  Let&#8217;s say, for instance, that you have four panes (making their indices 0, 1, [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Typically, if we want to programmatically select a particular AccordionPane within an ASP.NET AJAX Accordion control, we set the SelectedIndex property.  This is great if we know the exact order of our AccordionPanes at all times, but this isn&#8217;t always so.  Let&#8217;s say, for instance, that you have four panes (making their indices 0, 1, 2, and 3, respectively).  If we make the third one (index 2) invisible, now the fourth one has an index of 2.  So let&#8217;s create a method to select the AccordionPane by its ID instead.</p>
<p><strong>VB.NET</strong></p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">Public Sub SetPane(ByVal acc As AjaxControlToolkit.Accordion, ByVal PaneID As String)
    Dim Index As Integer = 0
    For Each pane As AjaxControlToolkit.AccordionPane In acc.Panes
        If (pane.Visible = True) Then
            If (pane.ID = PaneID) Then
                acc.SelectedIndex = Index
                Exit For
            End If
            Index += 1
        End If
    Next
End Sub</pre>
<p><strong>C#</strong></p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">protected void SetPane(AjaxControlToolkit.Accordion acc, string PaneID) {
    int Index = 0;
    foreach (AjaxControlToolkit.AccordionPane pane in acc.Panes) {
        if (pane.Visible == true) {
            if (pane.ID == PaneID) {
                acc.SelectedIndex = Index;
                break;
            }
            Index++;
        }
    }
}</pre>
<p>It is interesting to note that I attempted to create a client-side equivalent of this method.  However, the ID is not passed down from the server to the client-side behavior, making it impossible to access that propery from the client. </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=10&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2007/11/30/selecting-an-ajax-accordionpane-by-id/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
		<item>
		<title>Easy SQL &#8220;If Record Exists, Update It.  If Not, Insert It.&#8221;</title>
		<link>http://disturbedbuddha.wordpress.com/2007/11/29/easy-sql-if-record-exists-update-it-if-not-insert-it/</link>
		<comments>http://disturbedbuddha.wordpress.com/2007/11/29/easy-sql-if-record-exists-update-it-if-not-insert-it/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 16:57:25 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[SQL]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2007/11/29/easy-sql-if-record-exists-update-it-if-not-insert-it/</guid>
		<description><![CDATA[A very common scenario is the one where we want to update the information in a record if it already exists in the table, and if it doesn&#8217;t exist, we want to create a new record with the information. 
The most common solution to this problem is using IF EXISTS  (subquery).  This comes to mind first because [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A very common scenario is the one where we want to update the information in a record if it already exists in the table, and if it doesn&#8217;t exist, we want to create a new record with the information. </p>
<p>The most common solution to this problem is using IF EXISTS  (subquery).  This comes to mind first because it matches how we think about the problem (as you can see by the title of this article!).  We say &#8220;If the criterion exists in this initial subquery, then I&#8217;ll do this.  If not, I&#8217;ll do this other thing.&#8221;  This results in a <u>three-step process</u>:</p>
<ol>
<li>Do the subquery (SELECT whatever FROM wherever WHERE something).</li>
<li>Evaluate the EXISTS statement (is it there or not?).</li>
<li>Execute either the UPDATE or INSERT statement.</li>
</ol>
<p>Now, let&#8217;s try an &#8220;unnatural&#8221; shortcut.  I say unnatural because it doesn&#8217;t follow that &#8220;natural&#8221; logic occurring in our brain that I mentioned above.  Instead, let&#8217;s just do the update, and if it fails, then we&#8217;ll do the insert.  When the update fails, that just means that no rows were affected, not that an error was thrown.  Now we are down to a <u>one-step</u> (if the update succeeds) or <u>two-step process</u> (if we have to insert instead).  This is much more efficient!</p>
<p><strong>Example:</strong></p>
<p>This is not necessarily a practical example, but let&#8217;s say that we have a table called &#8220;Users&#8221; which has three fields:  &#8220;UserID&#8221;, &#8220;FirstName&#8221;, and &#8220;LastName&#8221;.  If a record already exists with the specified UserID, simply update it with the new @FirstName and @LastName values.  If it does not exist, create a new record with those values.</p>
<pre style="overflow:scroll;background-color:#cccccc;padding:2px;">CREATE PROCEDURE dbo.spAddUserName
     (
     @UserID AS int,
     @FirstName AS varchar(50),
     @LastName AS varchar(50)
     )
AS
     BEGIN
          DECLARE @rc int    

          UPDATE [Users]
             SET FirstName = @FirstName, LastName = @LastName
           WHERE UserID = @UserID   

          /* how many rows were affected? */
          SELECT @rc = @@ROWCOUNT    

          IF @rc = 0
               BEGIN
                    INSERT INTO [Users]
                                (FirstName, LastName)
                         VALUES (@FirstName, LastName)
               END         

     END</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=9&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2007/11/29/easy-sql-if-record-exists-update-it-if-not-insert-it/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
		<item>
		<title>View Source Trick for Pages with Partial Rendering</title>
		<link>http://disturbedbuddha.wordpress.com/2007/11/27/view-source-trick-for-pages-with-partial-rendering/</link>
		<comments>http://disturbedbuddha.wordpress.com/2007/11/27/view-source-trick-for-pages-with-partial-rendering/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 21:06:47 +0000</pubDate>
		<dc:creator>disturbedbuddha</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://disturbedbuddha.wordpress.com/2007/11/27/view-source-trick-for-pages-with-partial-rendering/</guid>
		<description><![CDATA[Many people when developing want to look at the browser’s View Source to make sure that things are being outputted correctly or to see where in the DOM certain things are showing up. However, if you are using the Ajax concept of partial rendering (usually via UpdatePanels), what you get is the initial state of [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Many people when developing want to look at the browser’s View Source to make sure that things are being outputted correctly or to see where in the DOM certain things are showing up. However, if you are using the Ajax concept of partial rendering (usually via UpdatePanels), what you get is the initial state of the page when it was first loaded before any partial page updates, not the state of the page as it is currently.</p>
<p>To see the “current” source for the page, simply paste the following code into your browser’s location bar. It’s a little long, but it covers most browsers.</p>
<pre style="overflow:scroll;font-family:'Courier New';background-color:#cccccc;padding:2px;">javascript:if (typeof(window.document.body.outerHTML) != 'undefined'){'&lt;xmp&gt;'+window.document.body.outerHTML+'&lt;/xmp&gt;'} else if (typeof(document.getElementsByTagName('html')[0].innerHTML) != &#8216;undefined&#8217;){ &#8216;&lt;xmp&gt;&#8217;+document.getElementsByTagName(&#8217;html&#8217;)[0].innerHTML+&#8217;&lt;/xmp&gt;&#8217;} else if (typeof(window.document.documentElement.outerHTML) != &#8216;undefined&#8217;){ &#8216;&lt;xmp&gt;&#8217;+window.document.documentElement.outerHTML+&#8217;&lt;/xmp&gt;&#8217;} else { alert(&#8217;Your browser does not support this.&#8217;) }</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/disturbedbuddha.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/disturbedbuddha.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/disturbedbuddha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/disturbedbuddha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/disturbedbuddha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/disturbedbuddha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/disturbedbuddha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/disturbedbuddha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/disturbedbuddha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/disturbedbuddha.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/disturbedbuddha.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/disturbedbuddha.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=disturbedbuddha.wordpress.com&blog=2133466&post=8&subd=disturbedbuddha&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://disturbedbuddha.wordpress.com/2007/11/27/view-source-trick-for-pages-with-partial-rendering/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/disturbedbuddha-128.jpg" medium="image">
			<media:title type="html">Disturbed Buddha</media:title>
		</media:content>
	</item>
	</channel>
</rss>