<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Alessandro Zifiglio</title><link>http://weblogs.asp.net/alessandro/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Beginners introduction to Jiffycms Open source HTML Editor</title><link>http://weblogs.asp.net/alessandro/archive/2009/03/22/beginners-introduction-to-jiffycms-open-source-html-editor.aspx</link><pubDate>Sun, 22 Mar 2009 14:30:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6991253</guid><dc:creator>alessandro</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=6991253</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2009/03/22/beginners-introduction-to-jiffycms-open-source-html-editor.aspx#comments</comments><description>    
&lt;p&gt;One of the things you will notice in ASP.NET today is that by default, out of the box there is no standard control representing a rich text editor. You will also notice that your only viable options are quite limited to : &lt;/p&gt;
    
&lt;ul style="list-style-type: lower-alpha;"&gt;
      
&lt;li&gt;FREETEXTBOX --while the name suggests it's free, what is free is only a subset of features while the full version is on a pay basis. &lt;/li&gt;
      
&lt;li&gt;FCKEditor --This is the most highly used editor in the market today due to it being opensource, however, mainly it's just a clientside product with several contributors having written serverside wrappers around the clientside library. The problem with this though is that the web control is simply a wrapper. &lt;/li&gt;
      
&lt;li&gt;You purchase a commercial license from third parties (Quite pricey).&lt;/li&gt;
    &lt;/ul&gt;
    
&lt;p&gt;Jiffycms HTML Editor is a rich text open source HTML editor with commercial grade features and is a great alternative to all A,B,C points above. It's written for ASP.NET and uses ASP.NET AJAX Extentions to the full potential. It is also a rich server side Web control requiring you to make very little effort to get it running as it uses the VS.NET designer at full potential too. There are just too many features and to list each here is not going to be possible, instead this article will focus on first time usage and specifically how to move the css generated by the WebControl to an external CSS file.&lt;/p&gt;
    
&lt;p&gt;Unlike most html editors, Jiffycms is a true WebControl without any extra dependencies and is packaged as a single dll. Since it is built on top of the AJAX Extensions library, which many people are already referencing in their pages due to their using the UpdatePanel or what not, this also means they are already referencing the AJAX Extensions library, the payload in Client library download size is minimized something which you will incur on other third party editors out there today since they tend to use they own custom libraries. &lt;/p&gt;
    
&lt;p&gt;Here in this post, I want to show case how easy it is to use the Jiffycms HTML Editor in your pages and how to perform some optimizations to get the best performance from your web apps by using an external CSS StyleSheet file. &lt;/p&gt;
    
&lt;ul style="list-style-type: decimal;"&gt;
      
&lt;li&gt;
        &lt;div&gt;Firstly, let's try to start from the basics and define a new WebSite Project for the purpose of this tutorial&lt;/div&gt;
        &lt;div&gt;
          &lt;img src="http://weblogs.asp.net/blogs/alessandro/jiffycms/createnewproject.jpg" alt="Create new project VS.NET" mce_src="http://weblogs.asp.net/blogs/alessandro/jiffycms/createnewproject.jpg"&gt;
        &lt;/div&gt;
      &lt;/li&gt;
      
&lt;li&gt;Let's download the Jiffycms HTML Editor dll from &lt;a href="http://jiffycms.codeplex.com" title="Jiffycms HTML Editor" mce_href="http://jiffycms.codeplex.com"&gt;Codeplex&lt;/a&gt;&lt;/li&gt;
      
&lt;li&gt;Now that we have the dll which is Jiffycms.Net.Toolkit.dll, we are ready to add it to our toolbox in VS.NET &lt;/li&gt;
      
&lt;li&gt;
        &lt;div&gt;Before you add it to your toolbox, to help you in better organizing all your custom controls, you may want to create a new tab in the toolbox first and then add the control in there.&lt;/div&gt;
        &lt;div&gt;
          &lt;img src="http://weblogs.asp.net/blogs/alessandro/jiffycms/addnewtab.jpg" alt="Add new tab in VS.NET Toolbox" mce_src="http://weblogs.asp.net/blogs/alessandro/jiffycms/addnewtab.jpg"&gt;
        &lt;/div&gt;
      &lt;/li&gt;
      
&lt;li&gt;
        &lt;div&gt;Now right click into your newly created tab empty area and select "Choose Items" from the context menu. You can also simply drag and drop the DLL into the empty area.&lt;/div&gt;
        &lt;div&gt;
          &lt;img src="http://weblogs.asp.net/blogs/alessandro/jiffycms/choose-items.jpg" alt="Choose Items context menu" mce_src="http://weblogs.asp.net/blogs/alessandro/jiffycms/choose-items.jpg"&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;img src="http://weblogs.asp.net/blogs/alessandro/jiffycms/dllbrowsing.jpg" alt="Browsing for Jiffycms HTML Editor dll" mce_src="http://weblogs.asp.net/blogs/alessandro/jiffycms/dllbrowsing.jpg"&gt;
        &lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
    
&lt;p&gt;When your done browsing to the dll you downloaded from codeplex, you should see it in your toolbox at this point and you are ready to start using this fine component.&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/jiffycms/toolboxready.jpg" alt="Jiffycms HTML Editor icon in toolbox" mce_src="http://weblogs.asp.net/blogs/alessandro/jiffycms/toolboxready.jpg"&gt;
    &lt;/div&gt;
    
&lt;p&gt;While you may not like working in designview in VS.NET, dragging and dropping the control from the toolbox onto your web form is going to allow the editor to make the initial configs in your web.config file automatically. The registrations it makes can be made manually, it's just a registration for a simple Httphandler in web.config.&lt;/p&gt;
    &lt;div&gt;If you prefer to do this manually, then make the following entry under the path Configuration/httpHandlers section for IIS6 is as follows :&lt;/div&gt;
    
&lt;table style="width: 100%;"&gt;
      &lt;tbody&gt;
        
&lt;tr&gt;
          
&lt;td style="vertical-align: top; width: 99%;"&gt;
            
&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;add&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;verb&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"*"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;path&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"jiffycms.axd"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"Jiffycms.Net.Toolkit.WebResourceHandler"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    
&lt;p&gt;For IIS7, you need to make an entry under the path  : Configuration/system.webServer/Handlers section as follows :&lt;/p&gt;
    
&lt;table style="width: 100%;"&gt;
      &lt;tbody&gt;
        
&lt;tr&gt;
          
&lt;td style="vertical-align: top; width: 99%;"&gt;
            
&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;add&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;verb&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"*"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;path&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"jiffycms.axd"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"WebResourceHandler"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;&lt;br&gt; type&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"Jiffycms.Net.Toolkit.WebResourceHandler"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;&lt;br&gt;                         preCondition&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"integratedMode"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    
&lt;p style="color: red;"&gt;Note: If your dragging and dropping the component from the toolbox, this is already done for you.&lt;/p&gt;
    
&lt;p&gt;After dragging and dropping the control at designtime, this is what the HTML Editor looks like in DesignView :&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/jiffycms/editor-designview.jpg" alt="Jiffycms HTML Editor in designview" mce_src="http://weblogs.asp.net/blogs/alessandro/jiffycms/editor-designview.jpg"&gt;
    &lt;/div&gt;
    
&lt;p&gt;oh great, we got designtime rendering of the editor. Now it's a matter of playing with the various properties in the property grid. Upon running the page you will notice lots of css output in the head section of your rendered page. While this is the default, you can chose to put the css in an external css file. Doing this will not only decrease the page payload but since the css is in an external css file, it will get cached by the browser, so that subsequent requests will be served from cache automatically.&lt;/p&gt;
    
&lt;p&gt;Fortunately this kind of change is not hard to do. You can use a designtime feature to collect all the runtime css generated by the control and manually copy it into an external CSS StyleSheet File.&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/jiffycms/cssextraction.jpg" alt="CSS extraction tool" mce_src="http://weblogs.asp.net/blogs/alessandro/jiffycms/cssextraction.jpg"&gt;
    &lt;/div&gt;
    &lt;div&gt;Just copy the css and paste it into an external style sheet, then reference the css file via ExternalStyleSheet Property &lt;/div&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/jiffycms/externalstylesheet.jpg" alt="Map external stylesheet to ExternalStyleSheet property" mce_src="http://weblogs.asp.net/blogs/alessandro/jiffycms/externalstylesheet.jpg"&gt;
    &lt;/div&gt;
    
&lt;p&gt;Note that every time you make a modification to the editor such as modify the styles in the designer or modify style dependent properties such as IconsMode, ToolbarMode etc, you will need to regenerate the css and update your css file manually. Fortunately if you have decided to go this route, you might also be editing the css yourself so this may not be an inconvenience after all.&lt;/p&gt;

&lt;div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2falessandro%2farchive%2f2009%2f03%2f22%2fbeginners-introduction-to-jiffycms-open-source-html-editor.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2falessandro%2farchive%2f2009%2f03%2f22%2fbeginners-introduction-to-jiffycms-open-source-html-editor.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6991253" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Opensource/default.aspx">Opensource</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET+AJAX/default.aspx">ASP.NET AJAX</category></item><item><title>Jiffycms HTML Editor V1.O released</title><link>http://weblogs.asp.net/alessandro/archive/2009/03/18/jiffycms-html-editor-v1-o-released.aspx</link><pubDate>Wed, 18 Mar 2009 19:45:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6976184</guid><dc:creator>alessandro</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=6976184</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2009/03/18/jiffycms-html-editor-v1-o-released.aspx#comments</comments><description>
    
    &lt;p&gt;&lt;a href="http://www.jiffycms.net" title="Jiffycms an online content management system" mce_href="http://www.jiffycms.net"&gt;Jiffycms&lt;/a&gt; HTML Editor V1.0 is an open source editor with commercial grade features most of which facilitate development and as you will see from this short showcase, embedding jiffycms HTML Editor into your 

pages is easy, straightfoward, requires no dependencies but above all, it does not require that you learn something new or setup your projects in a certain 

way etc. Jiffycms Editor simply works provided you know how to D R A G and D R O P.&lt;/p&gt;&lt;p&gt;I just put it up on &lt;a href="http://jiffycms.codeplex.com" title="Jiffycms HTML Editor on codeplex." mce_href="http://jiffycms.codeplex.com"&gt;CodePlex&lt;/a&gt;, so you can check it out right away if you like. In this article, I just want to showoff some of it's designtime capabilities. Even if your not used to or like using VS.NET in designmode, you might want to do exactly this since dragging and dropping on the designer surface will allow it to register a needed HttpHandler and the many properties and settings can be overwhelming for first time usage.&lt;br&gt;&lt;/p&gt;&lt;p&gt;Following are some key DesignTime features that you will appreciate. The HTML Editor itself comprises of a single dll with no other dependencies, so first 

thing you will notice if you love the Visual studio designer is that all you need to do is add it to your Toolbox. 
&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/toolbox-editor.jpg" mce_src="http://weblogs.asp.net/blogs/alessandro/toolbox-editor.jpg" alt="Jiffycms HTML Editor in VS.NET Toolbox"&gt;
    &lt;/div&gt;
    &lt;p&gt;
And that's it. That is likely the hardest work you will be doing. From there, it's only a matter of dragging and dropping the editor onto your page.
&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/editor-designview-vsnet.jpg" mce_src="http://weblogs.asp.net/blogs/alessandro/editor-designview-vsnet.jpg" alt="Jiffycms HTML Editor designview VS.NET"&gt;
    &lt;/div&gt;
    &lt;p&gt;Then, it's just a matter of making a few settings in the property grid.&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/editor-designview-properties.jpg" mce_src="http://weblogs.asp.net/blogs/alessandro/editor-designview-properties.jpg" alt="Jiffycms HTML Editor property grid 

VS.NET"&gt;
    &lt;/div&gt;
    &lt;p&gt;Toolbars, tabs, custom dictionaries, custom css classes and what not, all support designtime collection editors in VS.NET ; It just makes adding custom 

customizations real easy or if you prefer working manually in HtmlView, then you can do just that.&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/collections-designtime-editing.jpg" mce_src="http://weblogs.asp.net/blogs/alessandro/collections-designtime-editing.jpg" alt="Jiffycms HTML Editor collections 

editor VS.NET"&gt;
    &lt;/div&gt;
    &lt;p&gt;Or if you prefer to work in HtmlView, you can very well do just that&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/htmlview.jpg" mce_src="http://weblogs.asp.net/blogs/alessandro/htmlview.jpg" alt="Jiffycms HTML Editor HTMLView VS.NET"&gt;
    &lt;/div&gt;
    &lt;p&gt;By default, all css needed to render the htmleditor are embedded in the head section of your page at runtime. You can however extract all the 

autogenerated css using the apposite designer reachable through the SmartTag in VS.NET designer. &lt;br&gt;&lt;/p&gt;
    &lt;p&gt;You simply copy the css into an external css file, and then 

pass a reference to it via the ExternalStyleSheet property exposed by the editor and your good to go. This simply allows the css to be cachable by the 

browser and giving you the best of performance.&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/editor-css-extraction.jpg" mce_src="http://weblogs.asp.net/blogs/alessandro/editor-css-extraction.jpg" alt="Jiffycms HTML Editor CSS Extraction"&gt;
    &lt;/div&gt;
    &lt;p&gt;By default Jiffycms HTML editor renders icons for each item in the toolbar. This can quickly get overwhelming, request wise due to the many toolbar items. 

To improve performance, you may try imagesprite rendering instead. This groups icons in groups of 10-15 etc and this way, instead of 50 icons, you may end up 

with only 5 or less depending on how they are grouped. &lt;br&gt;&lt;/p&gt;
    &lt;p&gt;If you do not plan to change the icons or customize them, this is a great option. While customizations 

is possible in imagesprites mode, it's not as straight foward but still very much possible in the same way.&lt;/p&gt;
    &lt;div&gt;
      &lt;img src="http://weblogs.asp.net/blogs/alessandro/imagesprites.jpg" mce_src="http://weblogs.asp.net/blogs/alessandro/imagesprites.jpg" alt="Jiffycms HTML Editor Imagesprites Vs Icons"&gt;
    &lt;/div&gt;
  
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6976184" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Opensource+GPL/default.aspx">Opensource GPL</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/HTML+Editor/default.aspx">HTML Editor</category></item><item><title>ASP.NET MVC and no codebehind class </title><link>http://weblogs.asp.net/alessandro/archive/2008/12/02/asp-net-mvc-and-no-codebehind-class.aspx</link><pubDate>Tue, 02 Dec 2008 21:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6763177</guid><dc:creator>alessandro</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=6763177</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/12/02/asp-net-mvc-and-no-codebehind-class.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;ASP.NET MVC by default uses WebForms as the default View Engine. One gotcha you may not notice when adding a new *.aspx or *.master file, is that the respective codebehind classes (autogenerated ones) extend ViewPage and ViewMasterPage.&lt;br&gt;&lt;br&gt;I really do not like associating a codebehind class to my .aspx or master files even when using webforms. And no, I do not write spaghetti code. Normally what I have is that everything in my webform projects is a custom WebControl. Anyhow, back to MVC, so, with MVC i didn't think i'd want to start using codebehind because there was clearly no need for it. So i throw out my codebehind, remove the codebehind specific attributes in the page directive and attempt to run my page. &lt;br&gt;&lt;br&gt;Following is a sample of what my index.aspx looks like after i stripped out the codebehind class : &lt;/p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" %&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= Html.Encode(ViewData[&lt;span class="str"&gt;"Message"&lt;/span&gt;]) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;This however didn't go too well. I kept hitting errors about Html not existing, note that i have a line of code above : Html.Encode, which is really a call to the HtmlHelper class. Nor did it like ViewData, and errored on that too. As it turns out, and which was expected is that the ASP.NET webforms page and masterpage by default extend Page and MasterPage classes respectively. &lt;/p&gt;
&lt;p&gt;This means that we have to manually inherit both ViewPage and ViewMasterPage in their directives since these classes extends our normal Page/MasterPage classes with a few more properties exposed, Html and ViewData being some of these. &lt;/p&gt;
&lt;p&gt;the fix was to simply inherit PageView as below : &lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage"%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;and voila, i'm made. The same goes for master pages. By default your *.master inherits MasterPage class. What you want to do is instead inherit the MVC specific masterpage, which is ViewMasterPage class as follow :&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;I know, this is all non-trival however I didn't see this documented anywhere, so in case you end up with a typical error message eg : &lt;/p&gt;
&lt;p&gt;" CS0103: The name 'Html' does not exist in the current context " and you know you've referenced System.Web.Mvc etc, this might actually help you move forward :p &lt;/p&gt;
&lt;p&gt;Update : And while were at it, how do you use generics in the inheirts attribute in the page directive ? Well, it turns out that you need to use CLR Compatible Type name.&lt;/p&gt;
&lt;p&gt;The easiest and most effective method to getting this is to first get the output using the typeof() and retrieving the FullName of the type, which apparently is the CLR Compatible Type name and then add that in the inherits attribute eg : &lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyNameSpace.MyType&amp;lt;System.Web.Mvc.ViewPage&amp;gt;).FullName &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;This should output something like this :&lt;/p&gt;&lt;pre class="csharpcode"&gt;MyNameSpace.MyType`1[[System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, &lt;/pre&gt;&lt;pre class="csharpcode"&gt;Culture=neutral, PublicKeyToken=31bf3856ad364e35]]&lt;/pre&gt;
&lt;p mce_keep="true"&gt;The above is what you will add in your inherits attribute. If you care for a proper explanation, you are welcome to read the following two online resources : &lt;/p&gt;
&lt;p mce_keep="true"&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=104071" mce_href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=104071"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=104071&lt;/a&gt;&lt;/p&gt;
&lt;p mce_keep="true"&gt;and &lt;/p&gt;
&lt;p mce_keep="true"&gt;&lt;a href="http://forums.asp.net/t/1193721.aspx" mce_href="http://forums.asp.net/t/1193721.aspx"&gt;http://forums.asp.net/t/1193721.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6763177" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ViewPage/default.aspx">ViewPage</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/ViewMasterPage/default.aspx">ViewMasterPage</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/MVC/default.aspx">MVC</category></item><item><title>Conserving Resources When Writing BLOB Values to SQL Server and Streaming BLOB Values back to the Client</title><link>http://weblogs.asp.net/alessandro/archive/2008/09/22/conserving-resources-when-writing-blob-values-to-sql-server-and-streaming-blob-values-back-to-the-client.aspx</link><pubDate>Mon, 22 Sep 2008 23:22:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6638302</guid><dc:creator>alessandro</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=6638302</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/09/22/conserving-resources-when-writing-blob-values-to-sql-server-and-streaming-blob-values-back-to-the-client.aspx#comments</comments><description>
&lt;p&gt;&amp;nbsp;Reading and writing blob data to/from your database can be a resource hog, because it normally involves holding the entire stream in memory. Holding 10kb, 20, 100kb in memory might not be an issue, however as you start allowing larger file uploads, your application starts to feel the stress and easily starts to run out of resources. &lt;br&gt;&lt;br&gt;Particularly, say you had a relatively small file (2mb) your allowing users to upload from your pages. User A uploads, it's only 2mb, you have not exceeded your memory allocation yet. However, as more users try to upload simultaneously, now your allocating more memory slots at a time, eg. if they were 5 simultaneous users, that's 2*5 = 10mb, 100 users, then it's 2*100. &lt;br&gt;&lt;br&gt;This is all too stressful on your webserver, or atleast was until ASP.NET 2.0. Since, things have changed and now asp.net supports setting a diskThreshold that allows you to specify the amount of data buffered in server memory for the request. So, say you wanted to keep the default diskThreshold of 256 bytes, when the file is larger than 256bytes, asp.net begins to write the filestream to disk Versus keeping it in memory. This is just great because i remember back in the day, this was quite annoying. Glad it's fixed. This means we do nothing as far as the upload is concerned from the client to your webserver.&lt;br&gt;&lt;br&gt;Still, if we are storing the stream in SQL Server, now we have a whole new scenario, and the question remains, how do we stream this data to sql server while conserving memory ? Should we stream the entire data as is in one lump ? Wont that allocate memory on our database server before writing to the database field ? This is what i want to address. Basically, what we want to do is save our file stream to sqlserver in smaller chunks, that way our database server will allocate only enough memory for that little chunk before writing it to the database field, in this way conserving memory at the cost of write speed(no free lunch, i'm afraid). &lt;br&gt;&lt;br&gt;However, the price to pay in latency for streaming chunks of data to sql server might be well worth, because the alternative is to tax your database server when memory is available and to crash it (I assume it may crash when it runs out of memory. I have not tried personally. You may try that yourself if your feeling curious. Do not forget to share your findings if you do :P)&lt;br&gt;&lt;br&gt;Take, SQL SERVER Express edition as an example which has the imposed limit of 1gb memory. That's not a whole lot is it ? Streaming the data to sql server in chunks is actually not as taxing as it may seem. True, the write performance is degraded but you can regulate it by increasing/decreasing the size of your chunk to find a compromise.&lt;br&gt;&lt;br&gt;So, how do we do this ? SQL Server 2005 has a new feature that enables it to update a field with .WRITE ; as you stream your chunks it just appends it to the existing field. You can read about it here : &lt;a href="http://msdn.microsoft.com/en-us/library/ms177523.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms177523.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms177523.aspx&lt;/a&gt;&lt;br&gt;&lt;br&gt;To Quote the documentation from the above link : &lt;br&gt;Because the .WRITE clause cannot be used to modify a NULL column, the column is first populated with temporary data. This data is then replaced with the correct data by using the .WRITE clause&lt;br&gt;&lt;br&gt;Now, that's not cool! We can work around that nicely though. Ineffect, it does not even feel like were working around anything. I've basically followed microsofts own documentation located at : &lt;a href="http://msdn.microsoft.com/en-us/library/aa719771.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa719771.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa719771.aspx&lt;/a&gt;, which had the proper code, however, instead of .Write, it uses an older method that is not compatible with&amp;nbsp; the newer varbinary,varchar(max),nvarchar(max) datatypes supported by SQL Server 2005&amp;nbsp; as opposed to the older not recommeded types -&amp;gt; image, text, and ntext. &lt;br&gt;&lt;br&gt;Following is an extract of the code i use to stream chunks of data to sql server using the .Write method. The purpose of the sample code is to display how you can go about writing your own ofcourse. I have just ripped the piece of code out of my DAL with a few minor adjustments, so just running a copy/paste of the code below will or may not yield much depending on your level of expertise. I am just way too lazy to write a completely contained example so bear with me. As it is, this article has gotten longer than I want it to be.&lt;br&gt;&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InsertFile(&lt;span class="kwrd"&gt;string&lt;/span&gt; applicationName, Stream data,&lt;br&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; mimeType, &lt;span class="kwrd"&gt;string&lt;/span&gt; fileName)&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; fileId = -1;&lt;br&gt;    &lt;span class="kwrd"&gt;using&lt;/span&gt; (SqlConnection myConnection = GetSqlConnection())&lt;br&gt;    {&lt;br&gt;        myConnection.Open();&lt;br&gt;        SqlCommand cmd = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlCommand(DbOwner + &lt;br&gt;    &lt;span class="str"&gt;".DataFile_Insert"&lt;/span&gt;, myConnection);&lt;br&gt;        cmd.CommandType = CommandType.StoredProcedure;&lt;br&gt;        cmd.Parameters.Add(&lt;span class="str"&gt;"@applicationName"&lt;/span&gt;, &lt;br&gt;SqlDbType.NVarChar, 256).Value = applicationName;&lt;br&gt;        cmd.Parameters.Add(&lt;span class="str"&gt;"@mimeType"&lt;/span&gt;, &lt;br&gt;    SqlDbType.NVarChar, 50).Value = mimeType;&lt;br&gt;        cmd.Parameters.Add(&lt;span class="str"&gt;"@length"&lt;/span&gt;, &lt;br&gt;    SqlDbType.Int, 4).Value = data.Length;&lt;br&gt;        cmd.Parameters.Add(&lt;span class="str"&gt;"@fileName"&lt;/span&gt;, &lt;br&gt;    SqlDbType.NVarChar, 256).Value = fileName;&lt;br&gt;        SqlParameter fileIdParam = &lt;br&gt;cmd.Parameters.Add(&lt;span class="str"&gt;"@fileId"&lt;/span&gt;, SqlDbType.Int, 4);&lt;br&gt;        fileIdParam.Direction = ParameterDirection.Output;&lt;br&gt;        cmd.ExecuteNonQuery();&lt;br&gt;        &lt;span class="rem"&gt;// now insert in chunks&lt;/span&gt;&lt;br&gt;        fileId = (&lt;span class="kwrd"&gt;int&lt;/span&gt;)fileIdParam.Value;&lt;br&gt;    }&lt;br&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (fileId &amp;gt; -1)&lt;br&gt;    {&lt;br&gt;        &lt;span class="rem"&gt;//The size of the "chunks" &lt;/span&gt;&lt;br&gt;&lt;span class="rem"&gt;// 128 bytes, regulate at will&lt;/span&gt;&lt;br&gt;        InsertFileByChunks(fileId, data, 128);&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;note how we are calling InsertFileByChunks from our insert method above ? &lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InsertFileByChunks(&lt;span class="kwrd"&gt;int&lt;/span&gt; fileId, Stream data, &lt;span class="kwrd"&gt;int&lt;/span&gt; bufferLen)&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;using&lt;/span&gt; (SqlConnection myConnection = GetSqlConnection())&lt;br&gt;    {&lt;br&gt;        myConnection.Open();&lt;br&gt;        SqlCommand cmd = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlCommand(DbOwner + &lt;br&gt;&lt;span class="str"&gt;".DataFile_InsertChunk"&lt;/span&gt;, myConnection);&lt;br&gt;        cmd.CommandType = CommandType.StoredProcedure;&lt;br&gt;        cmd.Parameters.Add(&lt;span class="str"&gt;"@fileId"&lt;/span&gt;, &lt;br&gt;SqlDbType.Int, 4).Value = fileId;&lt;br&gt;        SqlParameter paramData = cmd.Parameters.Add(&lt;span class="str"&gt;"@data"&lt;/span&gt;, &lt;br&gt;    SqlDbType.VarBinary, 128);&lt;br&gt;        SqlParameter paramOffset = cmd.Parameters.Add(&lt;span class="str"&gt;"@offset"&lt;/span&gt;, &lt;br&gt;                SqlDbType.BigInt);&lt;br&gt;        cmd.Parameters.Add(&lt;span class="str"&gt;"@length"&lt;/span&gt;, &lt;br&gt;    SqlDbType.Int, 4).Value = bufferLen;&lt;br&gt;        &lt;span class="kwrd"&gt;using&lt;/span&gt; (BinaryReader br = &lt;span class="kwrd"&gt;new&lt;/span&gt; BinaryReader(data))&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] buffer = br.ReadBytes(bufferLen);&lt;br&gt;            &lt;span class="kwrd"&gt;int&lt;/span&gt; offset = 0;&lt;br&gt;            &lt;span class="kwrd"&gt;while&lt;/span&gt; (buffer.Length &amp;gt; 0)&lt;br&gt;            {&lt;br&gt;                paramData.Value = buffer;&lt;br&gt;                paramOffset.Value = offset;&lt;br&gt;                cmd.ExecuteNonQuery();&lt;br&gt;                offset += bufferLen;&lt;br&gt;                buffer = br.ReadBytes(bufferLen);&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;        data.Close();&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;As you can see the above method just writes chunks of data at a time(the accompanying stored procedure DataFile_InsertChunk uses .Write to update the field with the new chunks as they come in).&lt;br&gt;&lt;br&gt;And now the accompanying stored procedures DataFile_Insert and DataFile_InsertChunk : &lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;PROCEDURE&lt;/span&gt; [dbo].[DataFile_Insert]&lt;br&gt;    @applicationName nvarchar(256),&lt;br&gt;    @mimeType nvarchar(50), &lt;br&gt;    @length &lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;br&gt;    @fileName nvarchar(256),&lt;br&gt;    @fileId &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;output&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;AS&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @applicationId UNIQUEIDENTIFIER&lt;br&gt;    &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;  @ApplicationId = ApplicationId &lt;span class="kwrd"&gt;FROM&lt;/span&gt; dbo.aspnet_Applications &lt;br&gt;    &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; &lt;span class="kwrd"&gt;LOWER&lt;/span&gt;(@ApplicationName) = LoweredApplicationName&lt;br&gt;        &lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; &lt;br&gt;             dataFile (applicationId, &lt;span class="kwrd"&gt;data&lt;/span&gt;, mimeType, [length],  &lt;br&gt;            [fileName], dateCreated, lastDateModified)&lt;br&gt;        &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (@applicationId, 0x0, @mimeType, @length, @fileName,  &lt;br&gt;        GETDATE(), GETDATE())&lt;br&gt;        &lt;span class="kwrd"&gt;SET&lt;/span&gt; @fileId = SCOPE_IDENTITY()    &lt;br&gt;&lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;&amp;nbsp;Note above how we introduce the value 0x0 (null) as per the article on MSDN into the data field ? "data" is the name of the field that will be holding our data stream and is a varbinary type. The reason we introduce the value 0x0 is because .Write cannot write into a NULL field.&amp;nbsp; This is the workaround i was talking about earlier and it does not effect the appended chunks in anyway.&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;PROCEDURE&lt;/span&gt; [dbo].[DataFile_InsertChunk]&lt;br&gt;    @&lt;span class="kwrd"&gt;data&lt;/span&gt; varbinary(&lt;span class="kwrd"&gt;MAX&lt;/span&gt;), &lt;br&gt;    @length &lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;br&gt;    @fileId &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;output&lt;/span&gt;,&lt;br&gt;    @offset bigint&lt;br&gt;&lt;span class="kwrd"&gt;AS&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;UPDATE&lt;/span&gt; dataFile &lt;span class="kwrd"&gt;SET&lt;/span&gt; &lt;span class="kwrd"&gt;data&lt;/span&gt;.&lt;span class="kwrd"&gt;WRITE&lt;/span&gt;(@&lt;span class="kwrd"&gt;data&lt;/span&gt;, @offset, &lt;br&gt;@length) &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; fileId = @fileId    &lt;br&gt;END&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;As you can see, it all boils down to this. Quite simple indeed. the .WRITE method takes as argument your chunk, the offset and the length. Not much for me to add here. Oh one thing you may also want to note is that .WRITE is called via the field to which it needs to write to. so the syntax takes the form of -&amp;gt; fieldName.WRITE(...) ; in my case the field name is "data" as you can note from the code in the stored proc above.&lt;br&gt;&lt;br&gt;We have now successfully stored our file stream in chunks. Next we want to see how to retrieve our filestream in a similar manner, that way we do not hog resources on our webserver when binary content is requested, requiring us to stream it out from the database server to the webserver where our code streams it out again to the client. Firstly, I hope you are already familiar with an HttpHandler, if not you can look it up on google. &lt;/p&gt;

&lt;p&gt;An HttpHandler/Module is general knowledge so i'm not going to get into it. I've mapped somefile.ashx to my HttpHandler, that way, every request that comes in will be handled by my custom handler, where i request the file stream from the database and then stream it out again in chunks to the client. My HttpHandler looks like this : &lt;br&gt;&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BinaryDataHandler : IHttpHandler&lt;br&gt;{&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ProcessRequest(HttpContext context)&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; fileId;&lt;br&gt;    &lt;span class="kwrd"&gt;bool&lt;/span&gt; success = &lt;span class="kwrd"&gt;int&lt;/span&gt;.TryParse(&lt;br&gt;        context.Request.QueryString[&lt;span class="str"&gt;"fileId"&lt;/span&gt;], &lt;br&gt;            &lt;span class="kwrd"&gt;out&lt;/span&gt; fileId);&lt;br&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (success)&lt;br&gt;    {&lt;br&gt;        IDataReader r = FileManager.GetFileById(fileId);&lt;br&gt;        StreamData(r, context);&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; StreamData(IDataReader r, HttpContext context)&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (r.Read())&lt;br&gt;    {&lt;br&gt;        DataFileItem dfi = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataFileItem();&lt;br&gt;        dfi.Length = (r[&lt;span class="str"&gt;"length"&lt;/span&gt;] &lt;span class="kwrd"&gt;is&lt;/span&gt; DBNull) ? &lt;br&gt;                    -1 : (&lt;span class="kwrd"&gt;int&lt;/span&gt;)r[&lt;span class="str"&gt;"length"&lt;/span&gt;];&lt;br&gt;        dfi.MimeType = (r[&lt;span class="str"&gt;"mimeType"&lt;/span&gt;] &lt;span class="kwrd"&gt;is&lt;/span&gt; DBNull) ? &lt;br&gt;        &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty : (&lt;span class="kwrd"&gt;string&lt;/span&gt;)r[&lt;span class="str"&gt;"mimeType"&lt;/span&gt;];&lt;br&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (dfi.MimeType != &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty)&lt;br&gt;            context.Response.ContentType = dfi.MimeType;&lt;br&gt;        dfi.FileName = (r[&lt;span class="str"&gt;"fileName"&lt;/span&gt;] &lt;span class="kwrd"&gt;is&lt;/span&gt; DBNull) ? &lt;br&gt;        &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty : (&lt;span class="kwrd"&gt;string&lt;/span&gt;)r[&lt;span class="str"&gt;"fileName"&lt;/span&gt;];&lt;br&gt;        dfi.Extention = (r[&lt;span class="str"&gt;"extention"&lt;/span&gt;] &lt;span class="kwrd"&gt;is&lt;/span&gt; DBNull) ? &lt;br&gt;        &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty : (&lt;span class="kwrd"&gt;string&lt;/span&gt;)r[&lt;span class="str"&gt;"extention"&lt;/span&gt;];&lt;br&gt;        context.Response.AddHeader(&lt;span class="str"&gt;"Content-Disposition"&lt;/span&gt;, &lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"inline;filename={0}{1}"&lt;/span&gt;, &lt;br&gt;        dfi.FileName, dfi.Extention));&lt;br&gt;        context.Response.AddHeader(&lt;span class="str"&gt;"Content-Length"&lt;/span&gt;, &lt;br&gt;        dfi.Length.ToString());&lt;br&gt;        &lt;span class="kwrd"&gt;int&lt;/span&gt; dataOrdinal = r.GetOrdinal(&lt;span class="str"&gt;"data"&lt;/span&gt;);&lt;br&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!(r[dataOrdinal] &lt;span class="kwrd"&gt;is&lt;/span&gt; DBNull))&lt;br&gt;            StreamByteArrayInChunks(r, dataOrdinal, context);&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; StreamByteArrayInChunks(IDataReader r, &lt;span class="kwrd"&gt;int&lt;/span&gt; ordinal, &lt;br&gt;        HttpContext context)&lt;br&gt;{&lt;br&gt;&lt;span class="rem"&gt;//102400 is 100kb at a time buffer&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] buffer = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[102400];&lt;br&gt;    &lt;span class="kwrd"&gt;int&lt;/span&gt; index = 0;&lt;br&gt;    &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;)&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;long&lt;/span&gt; count = r.GetBytes(ordinal,&lt;br&gt;           index, buffer, 0, buffer.Length);&lt;br&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (count == 0)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;break&lt;/span&gt;;&lt;br&gt;        }&lt;br&gt;        &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br&gt;        {&lt;br&gt;            index = index + (&lt;span class="kwrd"&gt;int&lt;/span&gt;)count;&lt;br&gt;            context.Response.BinaryWrite(buffer);&lt;br&gt;            context.Response.Flush();&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;    &lt;span class="rem"&gt;//closes datareader + underlying db connection&lt;/span&gt;&lt;br&gt;    r.Close();&lt;br&gt;}&lt;br&gt;&lt;span class="rem"&gt;// Override the IsReusable property.&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsReusable&lt;br&gt;{&lt;br&gt;    get { &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;; }&lt;br&gt;}&lt;br&gt;}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;A few things i will explain quickly from the above code is how we retrieve an IDataReader from our DAL instead of retrieving a stream. The reason is i want to retrieve the filestream in chunks from the DataReader and every chunk i read from the database, i want to write it out to the client, as i receive the chunks without storing them in memory on my webserver where my application resides. &lt;br&gt;&lt;br&gt;Another thing you may want to notice is the usage of the Http Header Content-Disposition and Content-Length ; basically, it was important for me to flush out the file with the original filename when the user choses to save the file and Content-Disposition helped there. Whereas Content-Length helped ensure the filesize on the receiving end (the client) since without it i was getting errors unzipping a file for example where winzip complained that the file was corrupt :-)&lt;br&gt;&lt;br&gt;So that's pretty much it. And oh, the method in my DAL that returns the IDataReader follows : &lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; IDataReader GetFileById(&lt;span class="kwrd"&gt;int&lt;/span&gt; fileId)&lt;br&gt;{&lt;br&gt;    SqlConnection myConnection = GetSqlConnection();&lt;br&gt;    myConnection.Open();&lt;br&gt;    SqlCommand cmd = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlCommand(DbOwner + &lt;br&gt;            &lt;span class="str"&gt;".DataFile_GetFileById"&lt;/span&gt;, myConnection);&lt;br&gt;    cmd.CommandType = CommandType.StoredProcedure;&lt;br&gt;    cmd.Parameters.Add(&lt;span class="str"&gt;"@fileId"&lt;/span&gt;, &lt;br&gt;            SqlDbType.Int, 4).Value = fileId;&lt;br&gt;    SqlDataReader r = cmd.ExecuteReader(&lt;br&gt;                    CommandBehavior.CloseConnection);&lt;br&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; r;&lt;br&gt;}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;With that i think we have succeeded in conserving resources on both our database server and our Web server. One last thing, when you got this all working, experiment by changing the buffer size and regulate it to the write speed that is acceptable as per your standards. Basically from my tests on my dev machine, i was getting a download speed of 500KB - 517KB/sec with a buffer size of 100kb (102400 bytes). While setting the same buffer size to 10kb (10240bytes), i was getting a download speed of 50KB - 60KB/sec ; &lt;br&gt;&lt;br&gt;These tests are ofcourse based on what i see as i request a file handled through my custom httphandler above. These values are more or less the same i reckon when streaming the same data to sql server in chunks or a good approximation, so use that as a starting point to regulate the desired speed/latency required by your app based on how much resources your webserver/database server has. Normally, uploads are usually restricted to a certain amount by most ISP's so it means you can set a much smaller chunk size when streaming from your application to sql server. And increase the chunk size when streaming from your webserver to the client (since your requesting clients download speeds are significantly high). It will also depend on the bandwidth availability of your webserver and other factors ofcourse, but that's off topic.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="color: red; font-weight: bold;"&gt;Update 23&amp;nbsp; september&amp;nbsp; 2008 :&lt;/span&gt; &lt;br&gt;
One last thing i forgot to mention but my friend &lt;a href="http://www.filip.duyck.org/"&gt;filip duyck&lt;/a&gt; brought up is that now since we are sending the data in chunks to sql server (whilst reusing the same connection), it's still additional hits to our database server. So consider that too while you evaluate how big you want your chunks to be.
&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6638302" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/BLOB/default.aspx">BLOB</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/SQL+SERVER/default.aspx">SQL SERVER</category></item><item><title>Automatically reload reCAPTCHA when postingback via a partial refresh (UpdatePanel)</title><link>http://weblogs.asp.net/alessandro/archive/2008/09/09/automatically-reload-recaptcha-when-postingback-via-a-partial-refresh-updatepanel.aspx</link><pubDate>Tue, 09 Sep 2008 13:03:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6612983</guid><dc:creator>alessandro</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=6612983</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/09/09/automatically-reload-recaptcha-when-postingback-via-a-partial-refresh-updatepanel.aspx#comments</comments><description>
&lt;p&gt;So, today, i wanted to use reCAPTCHA. Since this is an online service I was a bit skeptical at first with regard to downtime. However their faq states the following :&lt;/p&gt;

&lt;blockquote&gt;reCAPTCHA has distributed locations and multiple servers.&lt;br&gt;&lt;/blockquote&gt;

&lt;p&gt;&amp;nbsp;With that, we know that the service should be available pretty much all the time. And honestly, if it's good enough to service facebook's massive user base, it's good enough for me. Fact is, many people are already familiar with the service and know what to expect and how to proceed. However, the deciding factor was the noble cause of this project. Basically for every captcha that is deciphered, you are actually helping decode a word in a book that was digitized for the public domain by volunteers using OCR(optical character reconigition). Sometimes there are a few words that an OCR cannot read and these are the words presented in the catpcha. So while fighting spam, you are actually helping digitize books. Brilliant! I was sold :P:P&lt;br&gt;&lt;br&gt;If your looking to using this captcha service, then, after signing up to the service on their site &lt;a href="http://www.reCaptcha.com" title="stop spam - read books" mce_href="http://www.reCaptcha.com"&gt;ReCAPTCHA&lt;/a&gt; , you shall be provided with a public/private key to access the service. And this is all you need, since they already have a custom web control that you can insert into your asp.net pages to communicate with their service and consume the captcha. You can inform yourself more about how to consume it from your webform pages here : &lt;a href="http://recaptcha.net/plugins/aspnet/" title="stop spam - read books" mce_href="http://recaptcha.net/plugins/aspnet/"&gt;reCAPTCHA AND ASP.NET&lt;/a&gt;&lt;br&gt;&lt;br&gt;Now, while this is all working nicely, getting it to play nice with the UpdatePanel might be difficult for some. I say that because i have read a few articles online with workarounds, when there was no need. So the goal here is to have the captcha automatically refresh itself, if the captcha words submitted were wrong. So lets see how to do just that : &lt;br&gt;&lt;br&gt;First, what you want to do is make sure that the UpdateMode for the updatepanel is set to conditional. This means, you are responsible for calling update on the updatepanel manually. We want to make this manual because if the captcha is invalid, then you do not want the updatepanel containing the captcha to refresh(this will only make recaptcha dissappear). Instead, we add a second updatepanel. Code speaks a thousand words, so lets take a look at functional code : &lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ScriptManager&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="ScriptManager1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:ScriptManager&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:UpdatePanel&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="UpdatePanel1"&lt;/span&gt; &lt;span class="attr"&gt;ChildrenAsTriggers&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; &lt;br&gt;&lt;span class="attr"&gt;UpdateMode&lt;/span&gt;&lt;span class="kwrd"&gt;="Conditional"&lt;/span&gt;&lt;br&gt;        &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ContentTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="TextBoxComment"&lt;/span&gt; &lt;span class="attr"&gt;TextMode&lt;/span&gt;&lt;span class="kwrd"&gt;="MultiLine"&lt;/span&gt; &lt;span class="attr"&gt;Rows&lt;/span&gt;&lt;span class="kwrd"&gt;="5"&lt;/span&gt;&lt;br&gt; &lt;span class="attr"&gt;Columns&lt;/span&gt;&lt;span class="kwrd"&gt;="35"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;recaptcha:RecaptchaControl&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="recaptcha1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;br&gt;&lt;span class="attr"&gt;Theme&lt;/span&gt;&lt;span class="kwrd"&gt;="red"&lt;/span&gt; &lt;span class="attr"&gt;PublicKey&lt;/span&gt;&lt;span class="kwrd"&gt;="6LcBAAAAAAAAAKtzVYRsIgOAAvCFge3iiMtf6hI9"&lt;/span&gt;&lt;br&gt;                &lt;span class="attr"&gt;PrivateKey&lt;/span&gt;&lt;span class="kwrd"&gt;="6LcBAAAAAAAAACQnFb_BI5tX7OxqC-C5RtROzx-S"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:UpdatePanel&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="UpdatePanel2"&lt;/span&gt; &lt;br&gt;&lt;span class="attr"&gt;ChildrenAsTriggers&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; &lt;span class="attr"&gt;UpdateMode&lt;/span&gt;&lt;span class="kwrd"&gt;="Conditional"&lt;/span&gt;&lt;br&gt;                &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ContentTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Label&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="labelError"&lt;/span&gt; &lt;br&gt;&lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;EnableViewState&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ContentTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:UpdatePanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="btnSubmit"&lt;/span&gt; &lt;span class="attr"&gt;ValidationGroup&lt;/span&gt;&lt;span class="kwrd"&gt;="GroupName"&lt;/span&gt; &lt;br&gt;&lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Submit"&lt;/span&gt; &lt;span class="attr"&gt;OnClick&lt;/span&gt;&lt;span class="kwrd"&gt;="btnSubmit_Click"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ContentTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:UpdatePanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;As you can note from the code above, we have two updatepanels. The second updatepanel contains a label to tell the user that the text they submitted is wrong. This is the only updatepanel we want to refresh when the captcha submitted is invalid. &lt;br&gt;&lt;br&gt;Now the minimum c# code to do our bidding :&amp;nbsp;&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; btnSubmit_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs args)&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!recaptcha1.IsValid)&lt;br&gt;        {&lt;br&gt;            labelError.Text = &lt;span class="str"&gt;"Incorrect, try again!"&lt;/span&gt;;&lt;br&gt;            labelError.ForeColor = System.Drawing.Color.Red;&lt;br&gt;            &lt;span class="rem"&gt;//Reload recaptcha&lt;/span&gt;&lt;br&gt;            ScriptManager.RegisterClientScriptBlock(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Page, &lt;br&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Page.GetType(),  &lt;span class="str"&gt;"whatever1"&lt;/span&gt;, &lt;br&gt;            &lt;span class="str"&gt;"Recaptcha.reload();"&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;br&gt;            UpdatePanel2.Update();&lt;br&gt;        }&lt;br&gt;    }&lt;/pre&gt;
&lt;p&gt;As you can note from above, the main code of interest here is the code we are registering via the ScriptManager, specifically -&amp;gt; "Recaptcha.reload(); what this will do is reload the captcha on the clientside when the second updatepanel refreshes whilst display an error message to our clients telling them to retry the captcha. I would love to make this article longer than it already is, however that's about it :-)&lt;/p&gt;

&lt;p&gt;Screen shots of what it looks like before we submit and what it looks like after below :&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;img src="http://weblogs.asp.net/blogs/alessandro/recaptcha-before.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/recaptcha-before.gif"&gt;&lt;/p&gt;

&lt;p&gt;After : note how the captcha is successfully reloaded via a partial postback. &lt;/p&gt;

&lt;p&gt;&lt;img src="http://weblogs.asp.net/blogs/alessandro/recaptcha-after.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/recaptcha-after.gif"&gt;&lt;/p&gt;

&lt;p style="color: red; font-weight: bold;"&gt;Update 26-september-2008 : The full source to the example code i have used throughout this posting : &lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" %&amp;gt;&lt;/span&gt;
&lt;span class="asp"&gt;&amp;lt;%@ Register TagPrefix="recaptcha" 
Namespace="Recaptcha" Assembly="Recaptcha" %&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; 
&lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;void&lt;/span&gt; btnSubmit_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs args)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (!recaptcha1.IsValid)
    {
        labelError.Text = &lt;span class="str"&gt;"Incorrect, try again!"&lt;/span&gt;;
        labelError.ForeColor = System.Drawing.Color.Red;
        &lt;span class="rem"&gt;//Reload recaptcha&lt;/span&gt;
        ScriptManager.RegisterClientScriptBlock(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Page,
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.Page.GetType(), &lt;span class="str"&gt;"whatever1"&lt;/span&gt;,
        &lt;span class="str"&gt;"Recaptcha.reload();"&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;);
        UpdatePanel2.Update();
    }
}
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ScriptManager&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="ScriptManager1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:ScriptManager&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:UpdatePanel&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="UpdatePanel1"&lt;/span&gt; &lt;span class="attr"&gt;ChildrenAsTriggers&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; 
&lt;span class="attr"&gt;UpdateMode&lt;/span&gt;&lt;span class="kwrd"&gt;="Conditional"&lt;/span&gt;
    &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ContentTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="TextBoxComment"&lt;/span&gt; &lt;span class="attr"&gt;TextMode&lt;/span&gt;&lt;span class="kwrd"&gt;="MultiLine"&lt;/span&gt; &lt;span class="attr"&gt;Rows&lt;/span&gt;&lt;span class="kwrd"&gt;="5"&lt;/span&gt;
&lt;span class="attr"&gt;Columns&lt;/span&gt;&lt;span class="kwrd"&gt;="35"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;recaptcha:RecaptchaControl&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="recaptcha1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; 
&lt;span class="attr"&gt;Theme&lt;/span&gt;&lt;span class="kwrd"&gt;="red"&lt;/span&gt; &lt;span class="attr"&gt;PublicKey&lt;/span&gt;&lt;span class="kwrd"&gt;="6LcBAAAAAAAAAKtzVYRsIgOAAvCFge3iiMtf6hI9"&lt;/span&gt;
            &lt;span class="attr"&gt;PrivateKey&lt;/span&gt;&lt;span class="kwrd"&gt;="6LcBAAAAAAAAACQnFb_BI5tX7OxqC-C5RtROzx-S"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:UpdatePanel&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="UpdatePanel2"&lt;/span&gt; 
&lt;span class="attr"&gt;ChildrenAsTriggers&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; &lt;span class="attr"&gt;UpdateMode&lt;/span&gt;&lt;span class="kwrd"&gt;="Conditional"&lt;/span&gt;
            &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ContentTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Label&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="labelError"&lt;/span&gt; 
&lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;EnableViewState&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ContentTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:UpdatePanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="btnSubmit"&lt;/span&gt; &lt;span class="attr"&gt;ValidationGroup&lt;/span&gt;&lt;span class="kwrd"&gt;="GroupName"&lt;/span&gt; 
&lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Submit"&lt;/span&gt; &lt;span class="attr"&gt;OnClick&lt;/span&gt;&lt;span class="kwrd"&gt;="btnSubmit_Click"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ContentTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:UpdatePanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6612983" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/UpdatePanel/default.aspx">UpdatePanel</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/reCaptcha/default.aspx">reCaptcha</category></item><item><title>Part 2 : Building and binding hierarchical data from the database to the ASP.NET Navigation Controls </title><link>http://weblogs.asp.net/alessandro/archive/2008/03/01/part-2-building-and-binding-hierarchical-data-from-the-database-to-the-asp-net-navigation-controls.aspx</link><pubDate>Sat, 01 Mar 2008 16:14:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5896556</guid><dc:creator>alessandro</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5896556</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/03/01/part-2-building-and-binding-hierarchical-data-from-the-database-to-the-asp-net-navigation-controls.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;&lt;A class="" href="http://weblogs.asp.net/alessandro/archive/2008/02/20/building-and-binding-hierarchical-data-from-the-database-to-the-asp-net-navigation-controls.aspx" mce_href="http://weblogs.asp.net/alessandro/archive/2008/02/20/building-and-binding-hierarchical-data-from-the-database-to-the-asp-net-navigation-controls.aspx"&gt;Around last week&lt;/A&gt;, I wrote about how we can make use of, some of the databinding capabilities of controls, that can bind to hierarchical data like the TreeView. While I covered pretty much everything, the data i was binding to was not deeply nested. Instead the data we were consuming was just 3 levels deep and that was that. &lt;/P&gt;
&lt;P mce_keep="true"&gt;Today, we will be binding to a hierarchical datasource whose nesting structure is not known and can go as deep as it wants. Here, also SQL servers&amp;nbsp;XML capabilities seem to come short since it does not support recursions. so&amp;nbsp;if our data had this kind of deep nesting, SQL Servers FOR XML queries are not helping out much and we'd need to combine XSLT to our FOR XML Query. &lt;/P&gt;
&lt;P mce_keep="true"&gt;Because of that, and since we end up using XSL for the transformation anyway, i'm going to be using the Dataset/XSLT approach I discussed in my previous post.&lt;/P&gt;
&lt;P mce_keep="true"&gt;First, lets create a "pages" table in Sql server with the following schema as you can see in the screen shot below :&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/table-schema.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/table-schema.gif"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;As you can note from above, we have a parentId field which is a self related field, related to the pageId in the same table. I personally prefer to move this field out to a junction table but each approach has it's pro's and con's, and this is simpler and serves our purpose :-)&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now, let's fill it with sample data, as you can note in the screenshot below :&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/Menu-Data.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/Menu-Data.gif"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;ohh perfect. Now it's time to put together some c# code : &lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Page_Load(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; sender, EventArgs e)
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;IsPostBack)
            XmlDataSource1.Data &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; GetHierarchicalData();
    }
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; GetHierarchicalData()
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; queryString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;SELECT pageId, pageDisplayName, parentId FROM pages;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        DataSet ds &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; DataSet(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Pages&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ConfigurationManager.
        ConnectionStrings[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;LocalSqlServer&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].ConnectionString;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (SqlConnection connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlConnection(
                   connectionString))
        {
            SqlDataAdapter adapter &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlDataAdapter();
            adapter.SelectCommand &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlCommand(
                queryString, connection);
            adapter.Fill(ds);

            ds.Tables[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].TableName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;PageItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; relate our tables&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;            DataRelation dr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; DataRelation(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;FK_pageId_parentId&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, 
            ds.Tables[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;PageItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].Columns[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;pageId&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;],
                        ds.Tables[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;PageItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].Columns[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;parentId&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;]);
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; we'd like the page items nested within 
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; each node for every child page.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;            dr.Nested &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
            ds.Relations.Add(dr);
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ds.GetXml();
    }&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;The xml returned by our dataset looks like this : &lt;A class="" href="http://weblogs.asp.net/blogs/alessandro/menuxml.txt" mce_href="http://weblogs.asp.net/blogs/alessandro/menuxml.txt"&gt;Dataset generated XML&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Notice how every pageId that had a corresponding parentId was nested within it's parent, forming a hiearchical set of data. This is just perfect, all thanks to the dataset's DataRelation capabilities and our setting Nested=true on the DataRelation. This kind of recusive nesting didn't seem supported by SQL Servers FOR XML queries, and if it was, then it's probably trival. I did find a few implicit hints in the documentation that recursive nesting was not supported on SQL Server FOR XML Queries, however i could be wrong (so please do your homework). &lt;/P&gt;
&lt;P mce_keep="true"&gt;Now our XSL file that does the recursion, but it's easier to make the transformation&amp;nbsp;now, because the data is already structured out nicely with the proper hierarchical structure. Only thing missing and why we need to perform transformation is as i explained in the previous post, we need the fields as attributes and not as xml elements. So here is our recursive xslt that does just that : &lt;BR&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;?&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;xml version="1.0" encoding="utf-8"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;?&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:stylesheet &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="1.0"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;
    xmlns:xsl&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://www.w3.org/1999/XSL/Transform"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:output &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;method&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="xml"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:template &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Menu"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; match&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="/"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Pages"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
      &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:for-each &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Pages/PageItem"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:variable &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="parentId"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="parentId/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="PageItem"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageId"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageId/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageDisplayName"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageDisplayName/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:call-template &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="processChildren"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
      &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:for-each&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
   &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:template&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;lt;!--&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; recursive template &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;--&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:template &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="processChildren"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:for-each &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="PageItem"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="PageItem"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageId"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageId/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageDisplayName"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageDisplayName/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:call-template &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="processChildren"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:for-each&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:template&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:stylesheet&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;And here is the output of this miraculous transformation : &lt;A class="" href="http://weblogs.asp.net/blogs/alessandro/menuxslt.txt" target=_blank mce_href="http://weblogs.asp.net/blogs/alessandro/menuxslt.txt"&gt;XSL Transformed XML&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Ohhh what beauty :-) and to complete, here is&amp;nbsp;the declarative code to bind our asp.net menu to the XmlDataSource control that consumes this data :&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;form &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="form1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;div&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:Menu &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Menu1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; MaximumDynamicDisplayLevels&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="1000"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
        Orientation&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Horizontal"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;
         DataSourceID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="XmlDataSource1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;DataBindings&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MenuItemBinding &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DataMember&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="PageItem"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
            TextField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageDisplayName"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ValueField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="pageId"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;DataBindings&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:Menu&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:XmlDataSource &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="XmlDataSource1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; XPath&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Pages/PageItem"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;
         TransformFile&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="~/MenuTransform.xsl"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:XmlDataSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;div&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;form&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;One gotcha you want to&amp;nbsp;watch out for is the root node showing in the menu. Since we do not want to show the starting node, we&amp;nbsp;explain this to the XmlDataSource nicely&amp;nbsp;by setting an XPath expression : XPath="Pages/PageItem". &lt;/P&gt;
&lt;P mce_keep="true"&gt;And below is our menu, when previewed in the browser. Time to congratulate ourselves on a job well done :-)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/Menu-Final-Product.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/Menu-Final-Product.gif"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;H1 style="COLOR: red"&gt;Update 21 May 2008&lt;/H1&gt;&lt;SPAN style="COLOR: red"&gt;A note i forgot to mention is that the XmlDataSource control has caching turned on by default. So in case you made a change in your xslt file and didn't see the change occuring, then you know it's using a cached copy. So make sure you disable caching during development.&lt;/SPAN&gt; &lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5896556" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/XML/default.aspx">XML</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/XSLT/default.aspx">XSLT</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Hierarchical+data/default.aspx">Hierarchical data</category></item><item><title>Building and binding hierarchical data from the database to the ASP.NET Navigation Controls</title><link>http://weblogs.asp.net/alessandro/archive/2008/02/20/building-and-binding-hierarchical-data-from-the-database-to-the-asp-net-navigation-controls.aspx</link><pubDate>Wed, 20 Feb 2008 21:30:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5830683</guid><dc:creator>alessandro</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5830683</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/02/20/building-and-binding-hierarchical-data-from-the-database-to-the-asp-net-navigation-controls.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;If we need to bind our navigations controls to hierarchical data we define manually ourselves in an xml file, this is easy as pie. However, things can get rather complicated or not so obvious when we need to generate this data from a database. First off, what can we use that is already provided to us for binding hierarchical data to our navigation controls in ASP.NET ? &lt;/P&gt;
&lt;P mce_keep="true"&gt;The already out of the box approach and ideal solution is to use the XmlDataSource control. This is quite a flexible datasource control since it not only enables us to define the path to our xml file containing the structure we need but also it allows us to define xml data to it via it's "Data" property. As you may have already guessed, because our data is going to be retrieved from our database, this is the property we shall be using :-)&lt;/P&gt;
&lt;P mce_keep="true"&gt;But first let's look at a sample data structure we may have in our database. I'm using the classic Northwind database. Let's imagine we want to display products grouped by category. So in short, for every category node, we want to show products under it. Following is a screenshot of the categories and products table and how they relate : &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH: 300px; HEIGHT: 487px" height=487 src="http://weblogs.asp.net/blogs/alessandro/categories_products.gif" width=300 mce_src="http://weblogs.asp.net/blogs/alessandro/categories_products.gif"&gt; &lt;/P&gt;
&lt;P&gt;The most common thing i see done is to manually loop through the records returned, create TreeNodes again manually and keep adding till you've build the TreeView or Menu, etc. Nothing wrong with this approach, since it works, however it is quite lengthy in code and time consuming too. &lt;/P&gt;
&lt;P&gt;But that's not the main reason why I'm writing this article. The main reason is that all these navigation controls in ASP.NET know how to consume hierarchical data. Once they have this, they know how to render themselves without you needing to do anything special. This is indeed some powerful databinding support that we miss out on when we go the manual approach. Here i am going to list two different approaches :&lt;/P&gt;
&lt;P mce_keep="true"&gt;1) DataSet and XSL Transformations, which while being clean and gives a more declarative model to work with (XSLT) versus the manual c# code approach. &lt;/P&gt;
&lt;P mce_keep="true"&gt;2)The second approach uses SqlServer's XML generating capabilities which allows us to skip XSLT and the dataset all together :-) &lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;H1&gt;DataSet and XSL Transformation approach:&lt;/H1&gt;
&lt;P&gt;---------------------------------------------------&lt;BR&gt;Note below how our select statements retrieves all categories, while the second statement retrieves all products. We then relate both these tables using a key field they have in common "CategoryID". We also use a dataset since it's providing us a lot of functionality like relating the tables after data retrieval and representing the data in xml.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; GetHierarchicalData()
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; queryString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;SELECT CategoryID, CategoryName, Description FROM Categories AS Category;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        queryString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;+=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;SELECT ProductID, CategoryID, ProductName FROM Products AS Product&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        DataSet ds &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; DataSet(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;TreeView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ConfigurationManager
.ConnectionStrings[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;LocalSqlServer&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].ConnectionString;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (SqlConnection connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlConnection(
                   connectionString))
        {
            SqlDataAdapter adapter &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlDataAdapter();
            adapter.SelectCommand &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlCommand(
                queryString, connection);
            adapter.Fill(ds);

            ds.Tables[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].TableName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Category&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
            ds.Tables[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;1&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].TableName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Product&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; relate our tables&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;            DataRelation dr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; DataRelation(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;FK_Products_Categories&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;,
ds.Tables[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Category&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].Columns[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;categoryId&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;],
                                ds.Tables[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Product&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].Columns[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;categoryId&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;]);
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; we'd like the products nested within 
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; each Category Node. Thank you :-)&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;            dr.Nested &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
            ds.Relations.Add(dr);
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ds.GetXml();
    }&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;A small sample output of the generated xml we get by calling dataset's GetXml() method is here -&amp;gt;&amp;nbsp; &lt;A href="http://weblogs.asp.net/blogs/alessandro/DataSetGenerated.txt"&gt;DataSet Generated XML&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;As you can see, we have our rootnode "TreeView", then a childNode "Category", which in turn will contain every product node within it that belongs to this category. This nesting was established when we created a relationship btw the Categories table and the Products table using a DataRelation, where we set Nested = true; on it. Enabling the Nested property did just what the name says. It nested all our products within it's specific Category node. &lt;/P&gt;
&lt;P&gt;While this is great, it does not help much with the TreeView control. Notice how every field our select statement returned is now an xml node and the data for the field is contained as inner text in our node. The TreeNodeBinding instead expects the fields to be contained as attributes, and the data as attribute values. Following screenshot is what we get when we run our TreeView bound to XmlDatasource &lt;BR&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/TreeView-Without-Transforma.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/TreeView-Without-Transforma.gif"&gt;&lt;/P&gt;
&lt;P&gt;Definately, not what we are after. This is because the datasets GetXml method returned :&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Category&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;CategoryID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;1&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;CategoryID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;CategoryName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Beverages&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;CategoryName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Description&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Soft drinks, coffees, teas, beers, and ales&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Description&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;while, what we need instead for the TreeNodeBinding to work is : &lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Category &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;CategoryID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; CategoryName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Beverages"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Description&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Soft drinks, coffees, teas, beers, and ales"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Had we the above xml structure with the fields defined as attributes we could easily create a TreeNodeBinding like this : &lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TreeNodeBinding &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Depth&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; DataMember&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Category"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TextField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CategoryName"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ValueField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CategoryID"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ToolTipField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Description"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;So, our next task is to transform our xml to represent fields as attributes and their data as attribute values. We can accomplish this easily using XSL Transformations. By defining some instructions in our XSL file, we can read our XML(what our dataset GetXml method output) and transform it into what the Navigation Controls expect, outputting a totally new XML document.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;?&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;xml version="1.0" encoding="utf-8"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;?&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:transform &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="1.0"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;
      xmlns:xsl&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://www.w3.org/1999/XSL/Transform"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:output &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;method&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="xml"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:template &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;match&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="/"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TreeView"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
      &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:for-each &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TreeView/Category"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Category"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="id"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CategoryID/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="name"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CategoryName/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="description"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Description/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:for-each &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Product"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Product"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
              &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="id"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductID/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
              &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
              &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="name"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:value-of &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;select&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ProductName/text()"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
              &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:attribute&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:for-each&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
      &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:for-each&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:element&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:template&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xsl:transform&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see from the above XSL, we have defined two for-each loops, one that loops through category nodes and the other that loops through product nodes. Very simple but powerful stuff indeed :-)&lt;/P&gt;
&lt;P&gt;The output xml after this transformation is &lt;A href="http://weblogs.asp.net/blogs/alessandro/XSLTransformedXML.txt"&gt;XSL Transformed Xml output&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;TreeView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Category&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;CategoryName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=""&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=""&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; description&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=""&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Product &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=""&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=""&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
   ...
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Category&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
...
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;TreeView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;ohh this is perfect. It was fun using XSL for the transmformation. Now, now, while it was fun, it can be a big pain in the behind if I'd have to do this all over again and again (Fortunately, i don't. Atleast now right now) :P&lt;/P&gt;
&lt;P&gt;So, can we have made this job easier ? Surely. SQL Server and FOR XML Queries to the rescue :-)&lt;/P&gt;
&lt;H1&gt;SQL Server and FOR XML Queries approach :&lt;/H1&gt;--------------------------------------------------- 
&lt;P&gt;Now, what if, instead of having to do all this manual labor, we could get SQL Server to do all the xml generation for us, the way we wanted it ? Very much possible indeed. In effect this does not even need any explainations. Code speaks a thousand words, so here it is, the same xml output but this time we didn't use XSLT, nor did we use a dataset and the code is even more minimized.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; GetHierarchicalDataFromSqlServer()
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; xml &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Empty;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; queryString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;@"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    SELECT Category.categoryName as [name], Category.categoryId as id, 
                                Category.description as description, 
                    Product.productName as name, Product.productId as id
                    FROM categories AS Category 
                    INNER JOIN products AS Product
                    ON Category.categoryId = Product.categoryId
                    ORDER BY Category.categoryId                    
                    FOR XML Auto, ROOT('TreeView')&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; connectionString &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ConfigurationManager.
ConnectionStrings[&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;LocalSqlServer&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;].ConnectionString;

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (SqlConnection connection &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlConnection(
                   connectionString))
        {
            SqlCommand SelectCommand &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SqlCommand(
                queryString, connection);
            connection.Open();
            XmlReader xr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; SelectCommand.ExecuteXmlReader();
            xr.MoveToContent();&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; move to the root node&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;            xml &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; xr.ReadOuterXml();
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; xml;
    }
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;The c# code to pass the XML data to our XmlDataSource bound to a treeView : &lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Page_Load(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; sender, EventArgs e)
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;IsPostBack)
            XmlDataSource1.Data &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; GetHierarchicalDataFromSqlServer();
    }&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;That's it. No fuss, SQL Server's xml generation capabilities are just outstanding. And here is the declarative code i used to bind this hiearchical data to a treeview&amp;nbsp;: &lt;BR&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;form &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="form1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;div&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TreeView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TreeView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; DataSourceID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="XmlDataSource1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;DataBindings&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                   &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TreeNodeBinding &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Depth&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; DataMember&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Category"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TextField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="name"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ValueField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="id"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ToolTipField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Description"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                   &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TreeNodeBinding &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Depth&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; DataMember&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Product"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; TextField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="name"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ValueField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="id"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;DataBindings&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TreeView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;div&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:XmlDataSource &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="XmlDataSource1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:XmlDataSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;form&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;And here below is a screenshot of the treeview rendering itself. Fantastic :-)&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/TreeView-After-XSLT.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/TreeView-After-XSLT.gif"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;H1 style="COLOR: red"&gt;Update 21 May 2008&lt;/H1&gt;&lt;SPAN style="COLOR: red"&gt;A note i forgot to mention is that the XmlDataSource control has caching turned on by default. So in case you made a change in your xslt file and didn't see the change occuring, then you know it's using a cached copy. So make sure you disable caching during development.&lt;/SPAN&gt; &lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5830683" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/XML/default.aspx">XML</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/XSLT/default.aspx">XSLT</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Hierarchical+data/default.aspx">Hierarchical data</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/SQL+SERVER+FOR+XML+QUERY/default.aspx">SQL SERVER FOR XML QUERY</category></item><item><title>Customizing the ChangePassword control and removing the required CurrentPassword field</title><link>http://weblogs.asp.net/alessandro/archive/2008/02/15/customizing-the-changepassword-control-and-removing-the-required-currentpassword-field.aspx</link><pubDate>Fri, 15 Feb 2008 15:47:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5794715</guid><dc:creator>alessandro</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5794715</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/02/15/customizing-the-changepassword-control-and-removing-the-required-currentpassword-field.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;It's very rare that what is already provided in asp.net under the Login controls fits my requirements out of the box without some tweaking. Not that any of these controls offer anything specialized, but certainly they are a big time saver if we can re-utilize their functionality. &lt;/P&gt;
&lt;P mce_keep="true"&gt;First some background as to why i personally want to customize the ChangePassword control to suit my needs : &lt;/P&gt;
&lt;P mce_keep="true"&gt;Password recovery is what i was after today, however i have hashed passwords, and recovery is impossible. If the user lost their password, then there is no way for me to know what their password is and send it back in clear text. &lt;/P&gt;
&lt;P mce_keep="true"&gt;The ideal solution is to reset the password, however the autogenerated password is quite ugly and quite hard to remember. What I've decided to do is send the email during password recovery, but as part of the email, instead of telling the user their old password(which i can't) , I'm instead going to ask them to click on a tokenized link that will guarantee to me that they are indeed the ones that requested the password, send them to the page where they can provide a new password, in the background i'd be autogenerating a password first ofcourse, then updating the password with their new password because the MembershipUser.ChangePassword(oldPassword, newPassword) method requires Old password as one of it's two parameters.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;This password change step, i'd like to be done using the ChangePassword control, however to my big surprise CurrentPassword Field is a required field that i cannot remove. This is also a field that I do not want asked for during the password change request(since my user has forgotten their password and are now going to provide their new pasword).&lt;/P&gt;
&lt;P mce_keep="true"&gt;There is ofcourse no property or method in this control that removes the CurrentPassword field requirement, below is a screenshot of the ChangePassword control in designview, as you can note, the highlighted field is the CurrentPassword field i do not want. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/ChangePassword1.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/ChangePassword1.gif"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I've done a quick look on google and in the asp.net/forums and didn't find anybody providing any proper solutions either,&amp;nbsp;mostly vague replies : &lt;A href="http://forums.asp.net/p/1189347/2038354.aspx"&gt;http://forums.asp.net/p/1189347/2038354.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;As you can read from the posts there, the issue seems to be two things which&amp;nbsp;were also my same issues&amp;nbsp;: &lt;BR&gt;1) Remove the current password label/TextBox &lt;BR&gt;2) Pass the new resetpassword to CurrentPassword Property which by the way is a getter only and not settable (SAD SAD)&lt;/P&gt;
&lt;P mce_keep="true"&gt;Both of these things are not supported in this control. So let's quickly fix requirement 1 and there are a couple of ways to fix this :&amp;nbsp;&amp;nbsp;&lt;BR&gt;a) You have to define a custom&amp;nbsp; &amp;lt;ChangePasswordTemplate&amp;gt;. This can be easily done by taking your ChangePassword control into DesignView in Visual studio, right click on the control and select "Convert to template". You can then switch to HtmlView and set the visibility of CurrentPasswordLabel, CurrentPassword and CurrentPasswordRequired controls.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;b) If you prefer to do this in code, then you can find the Label and TextBox for CurrentPassword and set its visiblity to false. Since a is a nobrainer, i'm including a sample code of method (b) : &lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;Label l &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (Label)changePassword1.ChangePasswordTemplateContainer.
    FindControl(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;CurrentPasswordLabel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (l &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)
    l.Visible &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;

TextBox tb &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (TextBox)changePassword1.ChangePasswordTemplateContainer.
FindControl(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;CurrentPassword&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (tb &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)
    tb.Visible &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;

RequiredFieldValidator rfv &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (RequiredFieldValidator)changePassword1.
ChangePasswordTemplateContainer.FindControl(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;CurrentPasswordRequired&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (rfv &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)
    rfv.Visible &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now that we have the fields we want disabled, let's head onto fix issue 2 : &lt;BR&gt;We can't pass the Autogenerated password to the CurrentPassword Property because its a getter only, however this getter returns the value from our CurrentPassword TextBox, and this job is done immidiately after ChangingPassword event fires. This is good news for us, so we can resolve issue 2 like this : &lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; changePassword1_ChangingPassword(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; sender, 
    LoginCancelEventArgs e)
{
    changePassword1.UserName &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; user.UserName;
        TextBox currentPassword &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (TextBox)changePassword1.
         ChangePasswordTemplateContainer.FindControl(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;CurrentPassword&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (currentPassword &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)
            currentPassword.Text &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; user.ResetPassword();
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Note that in the above code, user is a reference to a field of type&amp;nbsp;MembershipUser. Ok, that's it. Now we have what were after, look at the screenshot below :&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/ChangePassword2.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/ChangePassword2.gif"&gt;&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5794715" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Login+Controls/default.aspx">Login Controls</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/ChangePassword/default.aspx">ChangePassword</category></item><item><title>Reducing UpdatePanel bloat by utilizing UpdateMode="Conditional" and ChildrenAsTriggers="false"</title><link>http://weblogs.asp.net/alessandro/archive/2008/01/30/reducing-updatepanel-bloat-by-utilizing-updatemode-quot-conditional-quot-and-childrenastriggers-quot-false-quot.aspx</link><pubDate>Wed, 30 Jan 2008 11:41:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5676039</guid><dc:creator>alessandro</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5676039</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/01/30/reducing-updatepanel-bloat-by-utilizing-updatemode-quot-conditional-quot-and-childrenastriggers-quot-false-quot.aspx#comments</comments><description>Just the other day, i was playing around with my DataControls nested inside an updatepanel. While this was working well, since everypostback was being done via an ajax callback, the amount of traffic going back and forth was simply way too bloated. It's easy not to notice at first, because everything is working as expected. however imagine a simple situation as the following pseudo code below. Things could be very complex, depending on how many datacontrols you have and the level of nesting. 
&lt;P mce_keep="true"&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:updatepanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UpdatePanel1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:GridView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="GridView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; AutoGenerateSelectButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
        runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
        OnSelectedIndexChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="GridView1_SelectedIndexChanged"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:DetailsView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="DetailsView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; AutoGenerateEditButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;
            runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; OnModeChanging&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="DetailsView1_ModeChanging"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:DetailsView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:updatepanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;As you can note from the code, this is a simple GridView, which enables a DetailsView when a row in the GridView is selected. We then have an Edit button on the DetailsView that should send the DetailsView in edit mode when clicked. All nice so far. Now, this is going to work as advertised ofcourse, all postback is done silently in the background. But if you look closely enough, both the gridview and the DetailsView are contained within a single UpdatePanel, so obviously the postback caused from any child control nested in the updatepanel will cause the entire contents of the updatepanel to refresh and send back the collective rendered content to the client. &lt;/P&gt;
&lt;P&gt;Below screenshots is the traffic analysed through firebug (a firefox extention). Hilighted data denotes the extra data we do not need rendered to the client.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat1.gif"&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat1-Thumb.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat1-Thumb.gif"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;As you can note from the screenshots above, my clicking the select button in the gridview, which should be launching the DetailsView in turn, while i'd only need the rendering of the DetailsView send back to me (since the gridview shouldn't need to change), i actually end up with both the rendering of the GridView and the DetailsView. Indeed, there is extra data(the GridView) being rendered which we do not need.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Ok, this is indeed a problem. Were doing things wrongly. So, how do we cause only the DetailsView to render back instead ? One might quickly think, let's put each into their own individual UpdatePanels ? :-)&lt;/P&gt;
&lt;P&gt;So, let's try that. Nothing to be ashamed of. It was the first solution that came to my mind too :P&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UpdatePanel1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:GridView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="GridView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; AutoGenerateSelectButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
                    OnSelectedIndexChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="GridView1_SelectedIndexChanged"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UpdatePanel2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; UpdateMode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="conditional"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
         &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Triggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:AsyncPostBackTrigger &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ControlID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="GridView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; EventName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="RowCommand"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Triggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:DetailsView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="DetailsView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; AutoGenerateEditButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
                    OnModeChanging&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="DetailsView1_ModeChanging"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:DetailsView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;And here below is the screnshot of the traffic as seen through firebug. Hilighted data denotes the extra data we do not need rendered to the client.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat2.gif"&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat2-Thumb.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat2-Thumb.gif"&gt;&lt;/A&gt;&lt;BR&gt;As you can see, we ended up with the same data as before. Nothing has changed, even though we included them in two separate UpdatePanels. Strange ? Not really. If you think about it, both panels are included in the page, and by default, both panels have UpdateMode="Always" set on them, which&amp;nbsp;causes both to refresh upon an async callback. &lt;/P&gt;
&lt;P&gt;azzzz we have a problem indeed. Time to read the documentation :P&lt;/P&gt;
&lt;P&gt;The first thing the docs hint about are two things : UpdateMode="Conditional" versus the Default which is "Always" and the second thing is&amp;nbsp; ChildrenAsTriggers="false" ; both of which are handy. &lt;/P&gt;
&lt;P&gt;If my postback was being caused only by children in UpdatePanel2, i couldof just set UpdateMode="Conditional" on UpdatePanel1 and i'd actually achieve what i was after. Only UpdatePanel2's content will be send back to the client. However if you will note in my example above, a control in UpdatePanel1 is the one who is triggering the postback. This satisfies the "Conditional" bit and UpdatePanel1 also renders its contents. Again not what i'm after.&lt;/P&gt;
&lt;P&gt;In effect, i've had to set both UpdateMode="Conditional" and also set ChildrenAsTriggers="false" on UpdatePanel1. This stopped the unwanted behaviour. ChildrenAsTriggers property has a proper explaination in the documentation, you can look it up. In short, it simply stops any direct children from making it refresh. This is good for us and what we are after. &lt;/P&gt;
&lt;P&gt;That's just perfect. Using this combo, i can keep the panel i do not want updated, while letting the panel with the update trigger refresh at will. This also allows me to control who gets updated by calling the update method manually on the panel that interests me. For example if i edit a record in the detailsview and want to show the change in the gridview, i'd run the update operation and then right after that, call update on the panel that contains my gridview manually.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UpdatePanel1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; UpdateMode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="conditional"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
ChildrenAsTriggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:GridView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="GridView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; AutoGenerateSelectButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
                    OnSelectedIndexChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="GridView1_SelectedIndexChanged"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UpdatePanel2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Triggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:AsyncPostBackTrigger &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ControlID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="GridView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; EventName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="RowCommand"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Triggers&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:DetailsView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="DetailsView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; AutoGenerateEditButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
                    OnModeChanging&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="DetailsView1_ModeChanging"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:DetailsView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;here are the screenies, you can see, only the detailsview is now present in our callback. Just perfect.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat3.gif"&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat3-Thumb.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/UpdatePanelBloat3-Thumb.gif"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;While this is a simplistic example, had you many deeply nested updatepanels you can easily workout who gets updated and whose data gets rendered reducing bloat, using the same method i've mentioned above. Don't simply include EVERYTHING in one updatepanel or multiple and depend on the default, posting back un-necessary bloat on each callback. Firebug for Firefox and Fiddler for IE are both great tools for inspecting and analysing your callback traffic. Use either. I prefer firebug :p&lt;/P&gt;
&lt;P&gt;Ok, so that was easy(just set UpdateMode="conditional" ChildrenAsTriggers="false"), nonetheless i ended up with quite a lengthy post :x&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5676039" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/UpdatePanel/default.aspx">UpdatePanel</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/c_2300_/default.aspx">c#</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Ajax+extentions/default.aspx">Ajax extentions</category></item><item><title>Semantically correct markup and the casual table. Can they co-exist ?</title><link>http://weblogs.asp.net/alessandro/archive/2008/01/07/semantically-correct-markup-and-the-casual-table-can-they-co-exist.aspx</link><pubDate>Mon, 07 Jan 2008 10:11:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5563201</guid><dc:creator>alessandro</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5563201</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/01/07/semantically-correct-markup-and-the-casual-table-can-they-co-exist.aspx#comments</comments><description>&lt;P&gt;I am sure by now, everybody has been scorned upon for not using semantically correct markup. It's all over the web today. The message is clear, Web standards are important. Valid Xhtml is important but above all, SEMANTICALLY CORRECT MARKUP!&lt;/P&gt;
&lt;P&gt;What is Semantically correct markup ? First lets define semantics :&lt;BR&gt;Semantics refers to aspects of meaning, as expressed in language or other systems of signs.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;So, when we say semantically correct markup, we are reffering to the use of&amp;nbsp; the correct HTML element that best describes the content contained within as such giving it meaning. There is actually an HTML element for pretty much any type of content you may want to display. For example if we had a heading, then we have the &amp;lt;h1 element, if we had a paragraph, we can throw it in a &amp;lt;p element, had we a list, we can use a &amp;lt;ul element. Ever wanted to display a quote block ? Use the &amp;lt;quoteblock element. You got tabular data ? Then you can use the &amp;lt;table element and that's how it goes. There are just way too many html elements to list here but you get the idea.&lt;/P&gt;
&lt;P&gt;But, isn't Valid markup enough ? Today we are all moving out of quirks mode and into the XHTML arena. We can see many benefits coming from writing valid XHTML that does not send our browser in quirks mode (which would mean the browser will be performing many code checks to see where you messed up in your mark and try and correct it for you). Obviously valid XHTML markup means your page will be rendered faster by the browser than one that has to go in quirks mode.&lt;/P&gt;
&lt;P&gt;So back to our question, isn't valid XHTML markup enough ? What does semantically correct HTML bring to the table. Moreover, how is this rule enforced by the browser ? Well, it's not. However had you any common sense you would use the proper HTML element to achieve what your trying to do, because there is actually an element for pretty much any type of content you may have and there is no need to try and disguise or fake one element to perform like another. &lt;/P&gt;
&lt;P&gt;But is that it ? Yes, i think so, but not only. It has more uses. Using semantically correct HTML allows your applications to easily provide proper accessibility support, since you can place your markup in a linearized manner that allows it to be read from top to bottom and make sense without the styling obviously as will be the case with some useragents. &lt;/P&gt;
&lt;P&gt;But look, Google uses tables for layout. How bad is that, accessibility wise ? Well,it is possible to achieve accessibility with tables too as long as when the table is linearized, it's content is readable in a meaningful way by the useragent for the disabled, parsing the content, just maybe harder or impossible to do in a complex layout. Well, good for google, their layout is quite simple, so it does not surprise me that they never felt the itch to update their HTML and use semantically correct markup, since i doubt that investment would be bringing anything to their *table* anyway.&lt;/P&gt;
&lt;P&gt;I've read several claims that semantically correct markup helps in search engine optimizations as in search engines use particular HTML tags to give weight importance to what they index on your pages. I'll agree that the &amp;lt;title tag is important, but apart from that, I have not seen or heard of actual facts or claims made by the search engines themselves, so i'll leave that as a myth. Again let's not forget google, quite the example they are setting if this were to be true :-)&lt;/P&gt;
&lt;P&gt;I'll agree however that Valid XHTML markup on the other hand can help a search engine index your page better, since it is valid, without markup error, you also have a lighter weight page(since style and markup are not mixed up), making it easier for search engine bots to crawl, search and index your pages content. &lt;/P&gt;
&lt;P&gt;One thing i want to note before I continue is that semantically correct markup, is not the same as valid markup. A non-semantically structured page is also valid markup. Neither the browser or the XHTML schema enforces any rules on what kind of content is contained within the html elements.&lt;/P&gt;
&lt;P&gt;Now that we know what semantically correct markup is and what the benefits are, mostly it boils down to 3 things for me : &lt;BR&gt;1) Common sense, there is an html element for the type of content you want to display, so use it.&lt;BR&gt;2) Accessibility&lt;BR&gt;3) Works nicely with CSS layout, allowing us to keep elements in a certain order for accessibility + changing layout without needing to touch markup while were at it.&lt;/P&gt;
&lt;P&gt;Achieving semantically correct markup with ASP.NET today is quite a TASK. In most cases you might find an escape by resorting to css friendly adapters, while in some cases you don't have a choice like with Webparts whose render output is tables.&lt;/P&gt;
&lt;P&gt;I still feel however that a combination of both CSS layout and using a table where necessary or beyond our control is not so bad, so long as the table can be linearized(Acessibility is not lost in this manner). &lt;/P&gt;
&lt;P&gt;What maybe lost however, is the ability to use css layout on the table we just introduced. A table lays out it's cells and rows. Not much you can do with css to lay it out. But how big of a problem is that really ? We do have valid XHTML markup. &lt;BR&gt;And unless you are abusive and unless your layout is completely dependant on Grid layout, i believe css layout and a couple of tables when needed, provided that the table can be linearized for accessibility, i feel you have nothing to worry about.&lt;/P&gt;
&lt;P&gt;Using css layout, you can control the layout of elements on the page easily without touching markup. However, there are limitations to this. It is possible to want to have different views of a page based on certain conditions. Note, different views as in content being added or totally absent. In case we need to hide content, this can be accomplished, but hiding content via css does not stop it from rendering in the markup(which we can consider un-necessary&amp;nbsp;bloat). While&amp;nbsp;replacement of&amp;nbsp;content is pretty much impossible. We can basically work with elements in the markup, but we cannot add new elements without touching the markup. This is easily a requirement in many scenario's, so the only viable solution is to use templates.&lt;/P&gt;
&lt;P&gt;Using templates, we can easily have a different template for any view. In this manner, we are able to have markup in any way imaginable. At this point, css for layout while useful is coming short. Further more, even if we had tables in our layout, we can easily rearrange them or change them in any way possible since we are in contact with the markup. &lt;/P&gt;
&lt;P&gt;This is a common need, especially if your working on content management systems. Templates come into play here, and templates are files with actual markup in a different order or markup that is included in one template which does not have to be present in another and so forth. All things achievable on the serverside obviously, so it wont really matter that much if you used a tabular layout or a css layout, atleast wont as far as easy customizations and modifications are concerned. &lt;/P&gt;
&lt;P&gt;100% semantically correct markup is not easy today with ASP.NET, and not something i want to bother with investing too much time and effort over. Clearly it is indeed a time consuming task and the time spent to achieve it does not easily translate into something you can easily justify for when you end up not having enough time to spend in the real functionality of your application at hand.&lt;/P&gt;
&lt;P&gt;During development, i like to think of writing my code in a way that will require minimal amount of effort on my part since always i'm on a time frame, and then how i can easily maintain that same code.&amp;nbsp; The functionality and ease of use, maintainence and time spend to achieve the task at hand usually surpasses by far the requirement to maintain 100% semantically correct markup. I like to write semantically correct markup where it makes sense in time needed, code need to achieve the task and effort later to maintain that code.&lt;/P&gt;
&lt;P&gt;Ofcourse the big question when you throw in a table will be : Can your table be linearized ? When linearized is it meaningful ? Accessibility is a fundamental need in many projects.&lt;/P&gt;
&lt;P&gt;I hope with this post i'm not discouraging semantically correct markup but on the contrary, you should try to write semantically correct markup, however if i may be frank, there is no need to sacrifice time,ease of use or maintainence to achieve it at 100%, instead a "compromise" can exist.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5563201" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Css+Friendly+Adapter/default.aspx">Css Friendly Adapter</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/XHTML/default.aspx">XHTML</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/HTML/default.aspx">HTML</category></item><item><title>Tabmenu missing in the asp.net toolbox ? Not anymore!</title><link>http://weblogs.asp.net/alessandro/archive/2008/01/05/tabmenu-missing-in-the-asp-net-toolbox-not-anymore.aspx</link><pubDate>Sat, 05 Jan 2008 13:55:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5552368</guid><dc:creator>alessandro</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5552368</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/01/05/tabmenu-missing-in-the-asp-net-toolbox-not-anymore.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;One of the things i find lacking in asp.net is a Tab control. A tabbed UI is quite useful if not a very essential UI component that is not included in asp.net by default, however you already have all the tools necessary to make one. What i do to get a tabbed UI is combine the asp.net menu with the MultiView. Total cake ofcourse and does not require a blog post, however, what i want is a proper tabbed user interface. &lt;/P&gt;
&lt;P mce_keep="true"&gt;I want the selected menu item to blend in into the rest of the page showing the currently selected menu item is part of the current page/content in view. I've never really found an easy way out of this. Not to mention that using the menu control had it's usual bloat which i didn't want. Basically a menu control is a full fledged navigation control with all the bells and whistles of being able to provide additional menu items in a dropdown list of items etc, which included the un-necessary javascript files + a lot of un-necessary html and inline js script to render the menu itself. Ofcourse since i had no need or use for all this functionality, using the Menu control in it's default state was OVERKILL for my tabbed UI :-(&lt;/P&gt;
&lt;P mce_keep="true"&gt;Also, before i forget, One thing you can do is try and use the Tabs control (&lt;A href="http://asp.net/AJAX/AjaxControlToolkit/Samples/Tabs/Tabs.aspx"&gt;http://asp.net/AJAX/AjaxControlToolkit/Samples/Tabs/Tabs.aspx&lt;/A&gt;) in the AjaxControlToolKit. Unfortunately, many months ago i tried this tab control and it didn't fit my needs. Also, lets not forget that it relies on scripting when a tabbed UI can be achieved easily with a bit of html and css. &lt;/P&gt;
&lt;P mce_keep="true"&gt;One approach I had considered was roll my own tab control but if i'm going to invest all this development time and effort, i might as well use the tabs control in the ajaxcontroltoolkit whilst rewriting what extra functionality i needed. After all it is released under the MS shared code license and the source code is available :-) &lt;/P&gt;
&lt;P mce_keep="true"&gt;You have to remember that while rolling your own sounds always facinating and you feel almost always you can do it better than everybody else(and maybe you can), time is usually NEVER on your side and as a rule of thumb, you really want to reserve all of your time to the main functionality and tasks of your application and not get side tracked.&lt;/P&gt;
&lt;P mce_keep="true"&gt;So, if i were going to roll my own tab menu, i needed to do it in record time. The features i wanted were very simple : &lt;/P&gt;
&lt;P mce_keep="true"&gt;1) An easy to manage UI, allowing me to change the look as I wanted. So, preferably css layout.&lt;BR&gt;2) Minimum markup rendered to the client.&lt;BR&gt;3) Only render the active view to the client&lt;BR&gt;4) Avoid full postbacks and instead render views in partial postback&lt;BR&gt;5) Write as little code as possible to get the tabbed UI, since i shall be needed to reuse this functionality on several other pages.&lt;/P&gt;
&lt;P mce_keep="true"&gt;mmm tough ? Moreover how can we fix this un-wanted bloat while still using the menu + multiview for our tabbed UI ? &lt;/P&gt;
&lt;P mce_keep="true"&gt;Simple, CSS Friendly adapters is the way to go. The css friendly adapter for the menu control renders a proper Unordered list markup for the menu. It also does not include the un-necessary javascript files overhead which we wont be using. No more useless css and script injected into the page, but still now were left with making the UI usable as a tabbed UI and not a menu. I'll admit the CSS friendly adapters are not so bad, but they are so mmm "Downlevel" for lack of a better term(which is perfect for my tab) ;p&lt;/P&gt;
&lt;P mce_keep="true"&gt;The css friendly adapter for the menu control simply includes pretty much all we need but rendering an ordered list is not enough for us. We are now left with doing some work since like all things in life, there is no such thing as a free ride.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Or is there ? Well, I think we get lucky this time. There is :-) A quick google for tabbed CSS UI's and i ended up checking out : &lt;A href="http://unraveled.com/projects/html/css_tabs/"&gt;http://unraveled.com/projects/html/css_tabs/&lt;/A&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;This is a tabbed UI based on unordered lists done by Joshua Kaufman, and the license seems just about great(Creative commons) ; Adapting it to the CSS adapter menu control was ofcourse as easy as eating cake too. And the end result is a beautiful tabbed UI just as you can see on unraveled.com ; many thanks to Joshua Kaufman :-)&lt;/P&gt;
&lt;P mce_keep="true"&gt;Ofcourse, first you need to go download the CSS adapters from &lt;A href="http://www.asp.net/cssadapters/"&gt;http://www.asp.net/cssadapters/&lt;/A&gt; and set it up blah blah blah; One thing I also preffered was not to use an adapter but having a tabmenu control. I also do not use the CSS Friendly adapter controls. So the whole project with the entire adapter suite sitting in my project was quite annoying and I didn't want to use the css adapter for my menu, but only in my *tab menu's*. So since the bulk of the code was already written and provided with the CSS friendly adapters, it was as simple as walking in the park to pull together a custom TabMenu, that used most of the rendering logic provided in the CSS friendly menu adapter + combined it with the free css code from Joshua kaufman and were set. I'm including the full code for the tabmenu with a sample page as an attachment download to this post.&lt;/P&gt;
&lt;P mce_keep="true"&gt;First a screenshot of our finished product :&lt;BR&gt;&lt;IMG src="http://weblogs.asp.net/blogs/alessandro/TabbedUI.gif" mce_src="http://weblogs.asp.net/blogs/alessandro/TabbedUI.gif"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now, the code that rendered the above screenshot follows :&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"&gt;&amp;lt;%&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;@ Page Language&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;C#&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"&gt;&amp;lt;%&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;@ Register TagPrefix&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; Namespace&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;Demo.Controls&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;script &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; TabMenu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        string activeViewId &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; TabMenu1.SelectedItem.Value;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;string.IsNullOrEmpty(activeViewId))
        {
            View activeView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; GetActiveView(activeViewId);
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; (activeView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;!=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;)
                MultiView1.SetActiveView(activeView);
        }
    }
    public View GetActiveView(string activeViewId)
    {
        foreach (View v &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;in&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; MultiView1.Views)
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; (string.Compare(v.ID, activeViewId) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;)
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; v;
            }
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;;
    }
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;script&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;html &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;head &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Untitled Page&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;head&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;body&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;form &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="form1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:ScriptManager &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ScriptManager1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:ScriptManager&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UpdatePanel1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TabMenu &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TabMenu1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
        CssClassFile&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Css/TabbedUI.css"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
        OnMenuItemClick&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TabMenu1_MenuItemClick"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Items&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MenuItem &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="View 1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TabView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MenuItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MenuItem &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="View 2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Selected&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
            Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TabView2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MenuItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MenuItem &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="View 3"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TabView3"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MenuItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Items&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TabMenu&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MultiView &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MultiView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ActiveViewIndex&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:View &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TabView1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                        Tab view 1
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TextBox1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:View&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:View &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TabView2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                        Tab view 2
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TextBox2"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:View&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:View &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TabView3"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                        Tab view 3
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TextBox &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="TextBox3"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:View&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:MultiView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;form&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;body&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;html&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5552368" width="1" height="1"&gt;</description><enclosure url="http://weblogs.asp.net/alessandro/attachment/5552368.ashx" length="6536" type="application/x-zip-compressed" /><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/WebControls/default.aspx">WebControls</category></item><item><title>Failed to load viewstate ? Typical problem, with an obvious solution.</title><link>http://weblogs.asp.net/alessandro/archive/2008/01/04/failed-to-load-viewstate-typical-problem-with-an-obvious-solution.aspx</link><pubDate>Fri, 04 Jan 2008 14:51:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5547021</guid><dc:creator>alessandro</dc:creator><slash:comments>17</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5547021</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/01/04/failed-to-load-viewstate-typical-problem-with-an-obvious-solution.aspx#comments</comments><description>&lt;p mce_keep="true"&gt;Understanding viewstate is fundamental in asp.net, especially if you had run into : &lt;/p&gt;
&lt;p mce_keep="true"&gt;&lt;span style="color: green;"&gt;Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.&lt;/span&gt; &lt;/p&gt;
&lt;p mce_keep="true"&gt;The only way to resolve is a proper understanding of viewstate.&lt;/p&gt;
&lt;p mce_keep="true"&gt;&lt;a href="http://geekswithblogs.net/FrostRed/archive/2007/02/17/106547.aspx" mce_href="http://geekswithblogs.net/FrostRed/archive/2007/02/17/106547.aspx"&gt;http://geekswithblogs.net/FrostRed/archive/2007/02/17/106547.aspx&lt;/a&gt;&amp;nbsp;is a interesting post on viewstate that i happen to read today, pointed out to me by someone who ran into a viewstate problem about the control tree not matching and was clearly afraid of adding controls dynamically after reading some facts presented in that article. Who wouldn't :-)&lt;/p&gt;
&lt;p mce_keep="true"&gt;While the post gives us a very good understanding of viewstate and how it can fail, so i encourage you to read it first, might seem lengthy but I assure&amp;nbsp; you, it's quite interesting. However, when you're done, follow my rant here, since I feel it's important to know, that, the failure can only happen&amp;nbsp;when either done&amp;nbsp;deliberately as per the sample code in the post i linked to above or&amp;nbsp;to *not* understanding viewstate and how it works.&lt;/p&gt;
&lt;p mce_keep="true"&gt;So how can we easily avoid these failures ? Let's look at his first code example,&amp;nbsp;and build onto that :&lt;/p&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Page_Init(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; sender, EventArgs e)&lt;br&gt;    {&lt;br&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;IsPostBack)&lt;br&gt;        {&lt;br&gt;            Button btnClickMe &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Button();&lt;br&gt;            form1.Controls.Add(btnClickMe);&lt;br&gt;            btnClickMe.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Click me&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;        }&lt;br&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br&gt;        {&lt;br&gt;            Label label &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Label();&lt;br&gt;            form1.Controls.Add(label);&lt;br&gt;        }&lt;br&gt;    }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As you can note above, this is problematic, since the control into which viewstate is restored is matched by control index, so when the index changes, as is clear in the above code, because if btnClickMe was loaded in for example index [0], now upon postback, after the page has been recreated and rebuilt, the Label "label" is loaded in index [0] instead and takes the place of the button. So this means viewstate that was meant for the button is loaded into the label instead, and the output in the screen after clicking the button is "click me" which was clearly not provided to the label's text property.&lt;/p&gt;
&lt;p&gt;Now that we understand the problem, how can this sample apply in real world or why would anybody want to do something like this ? Basically in short, why is viewstate being utilized, if it's not needed after postback ? Button btnClickMe is not reloaded after postback, so it's safe to turn off viewstate on this control, and problem is solved.&lt;/p&gt;
&lt;p&gt;This is a typical situation where you deliberately want viewstate to fail, apart from that i see no real use to want to maintain viewstate, which is also bloat on a control that clearly is not utilizing it.&lt;/p&gt;
&lt;p&gt;so a rewrite ? here : &lt;/p&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Page_Init(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; sender, EventArgs e)&lt;br&gt;    {&lt;br&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;IsPostBack)&lt;br&gt;        {&lt;br&gt;            Button btnClickMe &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Button();&lt;br&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;//&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; note the addition of the following line&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;&lt;br&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;            btnClickMe.EnableViewState &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;; &lt;br&gt;            form1.Controls.Add(btnClickMe);&lt;br&gt;            btnClickMe.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Click me&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;        }&lt;br&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br&gt;        {&lt;br&gt;            Label label &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Label();&lt;br&gt;            form1.Controls.Add(label);&lt;br&gt;        }&lt;br&gt;    }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Otherwise, again as per the sample code above, had we been using viewstate, then the problem would resolve itself, if we recreated the control also after postback, which is one of the basic rules of dynamic controls creation. I say rules but really it's the logical thing to do since the page is destroyed after postback and asp.net will have no recollection of controls you added dynamically since memory is cleared, so it's upto you to build it up again manually :-)&lt;br&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Page_Init(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; sender, EventArgs e)&lt;br&gt;    {&lt;br&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;//&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; button will be created even after postback&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;&lt;br&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;        Button btnClickMe &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Button();&lt;br&gt;        btnClickMe.EnableViewState &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;        form1.Controls.Add(btnClickMe);&lt;br&gt;        btnClickMe.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Click me&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (IsPostBack)&lt;br&gt;        {&lt;br&gt;            Label label &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Label();&lt;br&gt;            form1.Controls.Add(label);&lt;br&gt;        }&lt;br&gt;    }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;So, bottom line, a proper understanding of viewstate, knowledge of&amp;nbsp;the page life cycle, so you know in what phase it's safe to build your control, which will guarantee that viewstate is reloaded into the control(so you load it prior to page_load), and you got it right.&amp;nbsp;For a proper understanding of the page life cycle, you can read the following&amp;nbsp;document on msdn : &lt;a href="http://msdn2.microsoft.com/en-us/library/ms178472.aspx?wt.slv=ColumnA"&gt;http://msdn2.microsoft.com/en-us/library/ms178472.aspx?wt.slv=ColumnA&lt;/a&gt;&lt;/p&gt;
&lt;p style="color: red;"&gt;Update Jan/04/2008: I forgot to&amp;nbsp;mention a gotcha, so here it is : &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Another gotcha you want to avoid is also the order of controls, that is, when you're loading a dynamic control, make sure the order in which you create it, has the same order when you recreate it. Confused, here let me explain better : &lt;/p&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Page_Init(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; sender, EventArgs e)&lt;br&gt;    {&lt;br&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (IsPostBack)&lt;br&gt;        {&lt;br&gt;            Label label &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Label();&lt;br&gt;            label.ID &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;label1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;            form1.Controls.Add(label);&lt;br&gt;            label.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;label&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;            &lt;br&gt;            Button btnClickMe &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Button();&lt;br&gt;            btnClickMe.ID &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;button1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;            form1.Controls.Add(btnClickMe);&lt;br&gt;            btnClickMe.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Click me&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;            &lt;br&gt;        }&lt;br&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;IsPostBack)&lt;br&gt;        {&lt;br&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;//&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;Now lets change the order &lt;br&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;//&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;during postback and we are&lt;br&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;//&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;recreating the controls&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;&lt;br&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;            Button btnClickMe &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Button();&lt;br&gt;            btnClickMe.ID &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;button1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;            form1.Controls.Add(btnClickMe);&lt;br&gt;            btnClickMe.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Click me&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;            &lt;br&gt;            Label label &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Label();&lt;br&gt;            label.ID &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;label1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;            form1.Controls.Add(label);&lt;br&gt;            label.Text &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;label&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br&gt;        }&lt;br&gt;    }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As you can note above, the order in which controls are added changes after postback. In this scenario what really happens ? The viewstate meant for the button is loaded into the label and the viewstate meant for the label is loaded into the button. So, you really want to be careful with the order in which you recreate your controls.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5547021" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Viewstate/default.aspx">Viewstate</category></item><item><title>Constructing a window frame to compliment the Popup and ModalPopup controls in AjaxControlToolkit library.</title><link>http://weblogs.asp.net/alessandro/archive/2008/01/03/constructing-a-window-frame-to-compliment-the-popup-and-modalpopup-controls-in-ajaxcontroltoolkit-library.aspx</link><pubDate>Thu, 03 Jan 2008 10:48:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5540996</guid><dc:creator>alessandro</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5540996</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2008/01/03/constructing-a-window-frame-to-compliment-the-popup-and-modalpopup-controls-in-ajaxcontroltoolkit-library.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;ok, so, to continue my previous post on the AjaxControlToolKit(ModalPopup), one of the things I feel might be convenient is the addition of a window frame panel that can be used alongside the Popup or ModalPopup control. &lt;/P&gt;
&lt;P mce_keep="true"&gt;Both the Popup and ModalPopup controls allow you to supply the Cancel button control id, which is normally the button that should close the Popup, usually represented by an 'X' symbol in the title bar of a window frame. We then have the title bar where we can include a title and the body part follows. &lt;/P&gt;
&lt;P mce_keep="true"&gt;While this is easy to construct manually using a set of panels and a button etc, it simply becomes ridiculously cumbersome and repetitive. What would be ideal is a custom panel control with all the "I am a beautiful window frame, simply provide me with body content" type functionality, that we can easily attach to our Popup or ModalPopup and have it render the window frame for us. &lt;/P&gt;
&lt;P mce_keep="true"&gt;Inheriting the panel and adding the extra titlebar container and a close button next to it is as easy as eating cake, so i'm not really going to try and explain the obvious ;p &lt;/P&gt;
&lt;P mce_keep="true"&gt;Also please note that below i have included a working solution that builds onto my previous post with the addition of an elegant window frame to our ModalPopup. Also along with the formatted source code for the control and usage, i've included a screenshot, so you know what to expect. Please, do try running the WebSite solution included in the attachment below as it will provide you a quick live preview + you can use it to further enhance and include additional features while testing your additions to the control :-)&lt;/P&gt;
&lt;P mce_keep="true"&gt;First the screenshot :&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://weblogs.asp.net/blogs/alessandro/ThePopupPanel.gif"&gt;&lt;IMG title=popupPanel style="WIDTH: 1024px; HEIGHT: 768px" height=768 alt=popupPanel src="http://weblogs.asp.net/blogs/alessandro/ThePopupPanel.gif" width=1024 mce_src="http://weblogs.asp.net/blogs/alessandro/ThePopupPanel.gif"&gt;&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Summary description for PopupPanel
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; PopupPanel : Panel
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; PopupPanel()
        {

        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit titleTopMarginValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit TitleTopMargin
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; 
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (titleTopMarginValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit.Empty)
                    titleTopMarginValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit.Parse(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;6px&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; titleTopMarginValue; 
            }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { titleTopMarginValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit closeButtonTopMarginValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit CloseButtonTopMargin
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; 
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (closeButtonTopMarginValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit.Empty)
                    closeButtonTopMarginValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit.Parse(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;8px&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; closeButtonTopMarginValue; 
            }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { closeButtonTopMarginValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }
    
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; The maximum number of characters to trim the title
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; and display an ellipses. If this property is not set,
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; no trimming will take place.
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; titleMaxiumCharsValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; TitleMaximumChars
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; titleMaxiumCharsValue; }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { titleMaxiumCharsValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }
    
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; titleValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Title
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; 
            { 
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.IsNullOrEmpty(titleValue))
                {
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (titleValue.Length &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; TitleMaximumChars)
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Format(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;{0}...&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, 
                            titleValue.Substring(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, TitleMaximumChars));
                }
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; titleValue;
            }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { titleValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Text displayed for the close button. If supplied,
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; instead of an image button, a linkbutton with this text
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; is used. Supply text to this property completely makes the
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; CloseButtonImageUrl property useless, since you can't have both.
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; closeButtonTextValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CloseButtonText
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; closeButtonTextValue; }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { closeButtonTextValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; closeButtonImageUrlValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Image to display in an ImageButton for closing the dialog window
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        [Editor(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(System.Web.UI.Design.ImageUrlEditor),
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(UITypeEditor))]
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CloseButtonImageUrl
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; closeButtonImageUrlValue; }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { closeButtonImageUrlValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; headerBackgroundImageValue;
        [Editor(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(System.Web.UI.Design.ImageUrlEditor), 
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(UITypeEditor))]
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; HeaderBackgroundImage
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; headerBackgroundImageValue; }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { headerBackgroundImageValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit headerHeightValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit HeaderHeight
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (headerHeightValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit.Empty)
                    headerHeightValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit.Parse(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;30px&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; headerHeightValue;
            }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { headerHeightValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; closeButtonIdValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CloseButtonId
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.IsNullOrEmpty(closeButtonIdValue))
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Format(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;{0}_CloseButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, 
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.ClientID);
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; closeButtonIdValue;
            }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            {
                closeButtonIdValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value;
            }
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit headerWidthValue;

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit HeaderWidth
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; 
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (headerWidthValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit.Empty)
                    headerWidthValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Unit.Parse(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;80%&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; headerWidthValue; 
            }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { headerWidthValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value; }
        }
    
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; dragHandleIdValue;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; DragHandleId
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.IsNullOrEmpty(dragHandleIdValue))
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Format(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;{0}_DragHandle&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, 
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.ClientID);
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; dragHandleIdValue;
            }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            {
                dragHandleIdValue &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; value;
            }
        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; RenderHeader(HtmlTextWriter writer)
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.IsNullOrEmpty(HeaderBackgroundImage))
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, 
                    ResolveUrl(HeaderBackgroundImage));
            writer.AddAttribute(HtmlTextWriterAttribute.Id, DragHandleId);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Cursor, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;move&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Height, 
                HeaderHeight.ToString());
            writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;0px&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.AddStyleAttribute(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;float&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;left&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Width, HeaderWidth.ToString());
            writer.AddStyleAttribute(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;text-indent&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;5px&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, 
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Format(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;{0} 0 0 0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, 
                TitleTopMargin.ToString()));
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.Write(Title);
            writer.RenderEndTag();&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;div - title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            writer.AddAttribute(HtmlTextWriterAttribute.Id, CloseButtonId);
            writer.AddStyleAttribute(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;float&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;right&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Cursor, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;pointer&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.IsNullOrEmpty(CloseButtonText))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Src, 
                    ResolveUrl(CloseButtonImageUrl));
                writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, 
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Format(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;{0} 0 0 0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, 
                    CloseButtonTopMargin.ToString()));
                writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;0px&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
                writer.RenderBeginTag(HtmlTextWriterTag.Img);
            }
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;#&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.Write(CloseButtonText);
            }
            writer.RenderEndTag();&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;img or anchor - close button&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;            writer.RenderEndTag();&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;div - header&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;override&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; RenderBeginTag(HtmlTextWriter writer)
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;base&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.RenderBeginTag(writer);
            RenderHeader(writer);
        }
    }
}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;first register it in your declarative code : 
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"&gt;&amp;lt;%&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;@ Register TagPrefix&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;Web&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; Namespace&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;Demo.Controls&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

then use as any other control :
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Web:PopupPanel  &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="PopupPanelDetailsView"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
    HeaderBackgroundImage&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="~/RedHeaderStrip.gif"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
    Title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Details View"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; CloseButtonImageUrl&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="~/close.gif"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
    Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="300px"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Web:PopupPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;h1&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;This is my content that will showup in the body area of the window&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;h1&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Web:PopupPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Ofcourse, this is a very basic window frame with the most basic functionality. You can further ehance it greatly with the extra features you need. Personally I use a slightly modified version in my own solutions and adding features that i do not need is a waste of time for me. So feel free to add what you need to it :-)&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5540996" width="1" height="1"&gt;</description><enclosure url="http://weblogs.asp.net/alessandro/attachment/5540996.ashx" length="619386" type="application/x-zip-compressed" /><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Ajax+extentions/default.aspx">Ajax extentions</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/AjaxControlToolKit/default.aspx">AjaxControlToolKit</category></item><item><title>UpdatePanel Css StyleSheet upon partial-refresh bug in IE</title><link>http://weblogs.asp.net/alessandro/archive/2007/12/31/updatepanel-css-stylesheet-upon-partial-refresh-bug-in-ie.aspx</link><pubDate>Tue, 01 Jan 2008 02:50:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5528221</guid><dc:creator>alessandro</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5528221</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2007/12/31/updatepanel-css-stylesheet-upon-partial-refresh-bug-in-ie.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;The update panel seems to have a bug when registering an external stylesheet or including css styles from within the contents that will be getting partially rendered. The bug only seems to occur in IE, works nicely in firefox. Impressive indeed. My problems started when i had a control that needed to render a link to an external stylesheet, which was quite mm easy and normal. I mean i've been there and done that plenty of times, however this time there were situations in which the stylesheet needed to be registered if my control was included in an updatepanel and kept invisible during inital load, while enabling it only upon a partial postback. TRICKY TRICKY TRICKY!&lt;BR&gt;&amp;nbsp;&lt;BR&gt;More over, there is an old bug opened and closed&amp;nbsp;with a&amp;nbsp;reason "this is by design". Seems awkward to me that this is by design and only effects IE :-(&lt;BR&gt;The url to the bug report is here : &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103134" mce_href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103134"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103134&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I resolved by registering the css in the OnInit phase of my custom control. Since this would run and register the css even if the control was disabled or invisible, which is what i was after, since it registered the control with the page on first load instead of trying to rendering the style link as part of my rendering for the control(which obviously didn't work in IE). A simplied piece of my code of how i have worked around this problem is as follows : &lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;override&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; OnInit(EventArgs e)
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;base&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.OnInit(e);
            ScriptManager sm &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ScriptManager.GetCurrent(Page);
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;sm.IsInAsyncPostBack)
            {
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; css &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Format(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;link rel=\"stylesheet\" &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;href&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;\&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;{0}\" type=\"text/css\" /&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, 
ResolveUrl(CssClassFile));

                ScriptManager.RegisterClientScriptBlock(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, 
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(MyBlahControl), &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;MyBlahId&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, css, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
            }
        }&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="COLOR: red"&gt;Update 01/01/2008 :&lt;/SPAN&gt; Please read the first two comments below.&amp;nbsp;CSS contianment from within the &amp;lt;body element violates xhtml specs and as such here is an update that includes the css in the &amp;lt;head section. Thanks to &lt;B&gt;Ram Krisna&lt;/B&gt; for pointing out/commenting this.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;override&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; OnInit(EventArgs e)
        {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;base&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.OnInit(e);
            ScriptManager sm &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ScriptManager.GetCurrent(Page);
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;sm.IsInAsyncPostBack)
            {
                HtmlLink l &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; HtmlLink();
                l.Href &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ResolveUrl(CssClassFile);
                l.Attributes.Add(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;rel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;stylesheet&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
                l.Attributes.Add(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;text/css&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
                Page.Header.Controls.Add(l);
            }
        }&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;A simplified test of what I feel is an open bug and should be fixed can be seen below. After clicking the button, the style applied to the label is lost and happens only in IE7, donno about previous versions since i have not tested : &lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"&gt;&amp;lt;%&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;@ Page Language&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;C#&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;script &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;

    protected &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt; Button1_Click(object sender, EventArgs e)
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000; BACKGROUND-COLOR: #f5f5f5"&gt;//&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000; BACKGROUND-COLOR: #f5f5f5"&gt; do something&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000; BACKGROUND-COLOR: #f5f5f5"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;    }
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;script&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;html &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;head &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Untitled Page&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;head&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;body&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;form &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="form1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;div&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:ScriptManager &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ScriptManager1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:ScriptManager&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UpdatePanel1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;lt;!--&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; 
                    Note below that for simplicity i am not
                    using an external stylesheet. Anyway, even with an external style
                    sheet the result is the same. The style is 
                    not applied after partial postback 
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;--&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;style &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="text/css"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000; BACKGROUND-COLOR: #f5f5f5"&gt;
                        .MakeGreen&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000; BACKGROUND-COLOR: #f5f5f5"&gt;background-color&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5"&gt;green&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"&gt;}&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000; BACKGROUND-COLOR: #f5f5f5"&gt;
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:Label &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Label1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="MakeGreen"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; 
                    runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Label"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:Label&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                    
                    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:Button &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Button1"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Partial refresh"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;
                        OnClick&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Button1_Click"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
                        
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ContentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:UpdatePanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;div&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;form&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;body&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;html&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;

&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5528221" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/UpdatePanel/default.aspx">UpdatePanel</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Ajax+extentions/default.aspx">Ajax extentions</category></item><item><title>Fixing the ModalPopup control in the AjaxControlToolKit</title><link>http://weblogs.asp.net/alessandro/archive/2007/12/27/fixing-the-modalpopup-control-in-the-ajaxcontroltoolkit.aspx</link><pubDate>Thu, 27 Dec 2007 11:00:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5507671</guid><dc:creator>alessandro</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/alessandro/rsscomments.aspx?PostID=5507671</wfw:commentRss><comments>http://weblogs.asp.net/alessandro/archive/2007/12/27/fixing-the-modalpopup-control-in-the-ajaxcontroltoolkit.aspx#comments</comments><description>&lt;div style="width: 80%;"&gt;
&lt;p&gt;While the ModalPopup control is nice, it comes short in pretty common usage scenario, especially when wanting to pop it from a DataControl like a GridView, Repeater, DataList and you have what. Specifically what i want to address in this post is being able to effectively use it from a DataControl while reducing bloat and make usage easier. As part of this post, I have included source code for a custom control with a small example page. It's an attachment to this post, you'll find it below.&lt;/p&gt;

&lt;p&gt;Unzip the Website application project and open it in visual studio by browsing to it from the Open Website dialog...&lt;br&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;So, i'm back to using the Ajax Extentions again yayy \o/&lt;br&gt;Today i wanted to use the ModalPopup control in the AjaxToolKit library. It was indeed working nicely for basic things until my application started to become more demanding. Specifically what i needed to do was to be able to popup the control via a button click, but then i didn't want to nest the modalpopup in every row of my gridview, Since i'd have one button per row, launching the same modalpop, while the data in the modalpopup changed based on what row i was clicking. I found it totally overkill and un-necessary to being forced to have 1 ModalPopup per row to launch my popup!&lt;br&gt;&lt;br&gt;To make things even worse, I was having issues with the ModalPopup dissappearing when a postback was instantiated by a control in the ModalPopup. The fix was ofcourse to call the Show method of the ModalPopup serverside to keep the popup displayed or else the postback wouldof refreshed it and keep it hidden again (as it would go back to its inital state, invisible and hidden).&lt;br&gt;&lt;br&gt;Again I had issues with this quick fix, since it just didn't work as advertised and became problematic. So, i set out to fix 2 things :&lt;br&gt;&lt;br&gt;1) I wanted 1 ModalPopup if all i had was a single ModalPopup to display via separate target controls, each on individual rows of a DataControl like a Gridview and reduce un-necessary code bloat.&lt;br&gt;&lt;br&gt;2) I wanted the ModalPopup to stop the dissappear act if a postback was initialized when the ModalPopup was in view.&lt;br&gt;&lt;br&gt;&lt;br&gt;I ended up ofcourse writing a server control that is easy to use, and reuse since i'd be needing this functionality on several other pages, but above all, i didn't really want to write too much code and above all, i wanted to use the ModalPopup, while fixing the problems it had, not reinventing the control. So here is how i tacked the problem. Firstly, this is how you use the control declaratively : &lt;br&gt;&lt;br&gt;&amp;lt;MyControl:DataControlModalPopup ID="DataControlModalPopup1" runat="server" &lt;br&gt;ModalPopupBehaviourId="DataControlModalPopupBehavior1" TargetControls="GridViewLinkButtonSelect,DetailsViewLinkButtonUpdate,DetailsViewLinkButtonCancel,DetailsViewLinkButtonDelete" /&amp;gt;&lt;br&gt;&lt;br&gt;As you can note above, the control expects 2 properties. &lt;br&gt;1) ModalPopupBehaviourId : This is the behaviour id you passed to the ModalPopup in your page. This is also how this control can find the ModalPopup js class instance created by the modalPopup control&lt;br&gt;&lt;br&gt;2) TargetControls : Expects a comma delimited list of postback control ids that you may need to &lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;a) Launch the control&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;b) Make postbacks once the popup control is shown(we want to fix the dissappearing act)&lt;br&gt;&lt;br&gt;One thing to note is that if you have a button on every row of your DataControl that is launching the ModalPopup, you only need to take the id you provided to the control. So say you provided the button an id of GridViewLinkButtonSelect, the final client id is an autogenerated id with NamingContainer namespaces prefixed : MyGridView_ctl01_GridViewLinkButtonSelect ; In this manner asp.net is able to autogenerate a unique id for the button repeated on each row, which will change eg : &lt;br&gt;&lt;br&gt;MyGridView_ctl01_GridViewLinkButtonSelect&lt;br&gt;MyGridView_ctl02_GridViewLinkButtonSelect&lt;br&gt;MyGridView_ctl03_GridViewLinkButtonSelect&lt;br&gt;&lt;br&gt;etc..&lt;br&gt;&lt;br&gt;You do not need to bother with the autogenerated id. all you need to do is pass the id of the control once, so in this case we pass only GridViewLinkButtonSelect as one of the control ids to TargetControls eg : &lt;br&gt;&lt;br&gt;TargetControls="GridViewLinkButtonSelect,DetailsViewLinkButtonUpdate,DetailsViewLinkButtonCancel,DetailsViewLinkButtonDelet"&lt;br&gt;&lt;br&gt;Note how we have included GridViewLinkButtonSelect in the list, while this is not the autogenerated id, this is all we need. &lt;br&gt;&lt;br&gt;Ok, enough with the rant already, lets get to see a proper working code example on usage :&lt;br&gt;&amp;nbsp;&lt;br&gt;1) A simple gridview nested in an UpdatePanel, with a select button on each row&lt;br&gt;2) Upon selecting the button, trigger a postback and popup a DetailsView in a ModalPopup&lt;br&gt;3) Make a postback from the detailsview when trying to go in edit mode and update the record and not experience the ModalPopup dissappearing act.&lt;br&gt;&lt;br&gt;Ok, time for a small example, well, i was hoping to make it minimum, looks a bit long but compared to real world usage scenario this is nothing and quite minimal :p&lt;br&gt;&lt;/p&gt;

&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:UpdatePanel &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="UpdatePanel1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;ContentTemplate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:Panel &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="PanelDetailsView"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; BackColor&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Gray"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    style&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="display:inline;"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:LinkButton &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="LinkButtonClose"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; Text&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Close"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:LinkButton&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:DetailsView &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="DetailsView1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; SkinID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="DetailsView1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    DataSourceID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ObjectDataSourceDetailsView"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;
        runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; OnModeChanging&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="DetailsView1_ModeChanging"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Fields&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:TemplateField&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
                    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:Button &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ButtonEdit"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; CommandName&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Edit"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
                    runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; Text&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Edit"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EditItemTemplate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
                    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:Button &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ButtonUpdate"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; CommandName&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Update"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
                    runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; Text&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Update"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EditItemTemplate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:TemplateField&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Fields&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:DetailsView&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:Panel&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:GridView &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="GridView1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; SkinID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="GridView1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    DataSourceID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ObjectDataSourceGridView"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;
    runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; OnRowCommand&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="GridView1_RowCommand"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Columns&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:TemplateField&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:Button &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ButtonSelect"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; CommandName&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Select"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
                CommandArgument&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;='&amp;lt;%# &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Container.DataItem %&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'
                    runat="server" Text="Select" /&amp;gt;
            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:TemplateField&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Columns&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:GridView&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Ajax:DataControlModalPopup &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="DataControlModalPopup1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    ModalPopupBehaviourId&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ModalPopup1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;
    TargetControls&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ButtonSelect,ButtonEdit,ButtonUpdate,LinkButtonClose"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;

    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:HiddenField &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="HiddenFieldDummy1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;

    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;AjaxToolKit:ModalPopupExtender &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ModalPopup1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    BehaviorID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ModalPopup1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;
    DropShadow&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="true"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; TargetControlID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="HiddenFieldDummy1"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    CancelControlID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="LinkButtonClose"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    PopupControlID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="PanelDetailsView"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;
    BackgroundCssClass&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="modalBackground"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; 
    RepositionMode&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="RepositionOnWindowScroll"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;AjaxToolKit:ModalPopupExtender&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;ContentTemplate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;
    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;asp:UpdatePanel&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now, one thing to note here is how the ModalPopupExtender's TargetControlID is set to a dummy hiddenField. Unfortunately I had to resort to this trick since not setting a targetID would cause the ModalPopupExtender to throw an error message making this propery obligatory. &lt;/p&gt;

&lt;p&gt;Another thing to also note is that we passed the ID of the controls to our custom controls TargetControls property (but we did not pass the autogenerated client ID) ; what this means is that internally the custom control is written to fix the problem by checking who is posting back and matching it to the list of id's supplied to TargetControls. &lt;/p&gt;

&lt;p&gt;The matching is done using the indexOf method, which for example can find : LinkButtonSelect in an id that was MyGridView_ctl01_GridViewLinkButtonSelect, so while we could pass the clientID, we didn't(for convenience) which means you are left to making sure that the ID you give your postback buttons do not collide with other buttons in the page. This is not a problem for me in 99.9% of the cases in my usage scenario and problem in most real world usage scenario. If it were then make sure you pass the ClientID :-)&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5507671" width="1" height="1"&gt;</description><enclosure url="http://weblogs.asp.net/alessandro/attachment/5507671.ashx" length="616971" type="application/zip" /><category domain="http://weblogs.asp.net/alessandro/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/AjaxControlToolKit/default.aspx">AjaxControlToolKit</category><category domain="http://weblogs.asp.net/alessandro/archive/tags/ModalPopup/default.aspx">ModalPopup</category></item></channel></rss>