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

<channel>
	<title>Nexus</title>
	<atom:link href="http://blog.nus.edu.sg/nexus/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nus.edu.sg/nexus</link>
	<description>Just another Your New Edublogs Campus Site weblog</description>
	<lastBuildDate>Mon, 17 Aug 2009 15:36:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>I&#8217;ve moved</title>
		<link>http://blog.nus.edu.sg/nexus/2009/08/17/ive-moved/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/08/17/ive-moved/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 15:36:11 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=110</guid>
		<description><![CDATA[Previously Nexus related along with ASP.NET development entries have been mixed in this blog.
With effect from Aug 2009, all non nexus related blog posts can now be found at http://jefferytay.wordpress.com
]]></description>
			<content:encoded><![CDATA[<p>Previously Nexus related along with ASP.NET development entries have been mixed in this blog.</p>
<p>With effect from Aug 2009, all non nexus related blog posts can now be found at <a href="http://jefferytay.wordpress.com" target="_self">http://jefferytay.wordpress.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/08/17/ive-moved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tabcontrols and Multiple Gridviews</title>
		<link>http://blog.nus.edu.sg/nexus/2009/04/23/tabcontrols-and-multiple-gridviews/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/04/23/tabcontrols-and-multiple-gridviews/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 03:18:20 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=107</guid>
		<description><![CDATA[If you have a TabContainer with multiple Tabs, and more than 1 tab have a gridview, any postback actions on the gridview will cause your tabcontainer to jump back to the first tab if you are not did not enclose the TabContainer in an update panel.
Digging into the source code reveals that the ClientStateField property [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a TabContainer with multiple Tabs, and more than 1 tab have a gridview, any postback actions on the gridview will cause your tabcontainer to jump back to the first tab if you are not did not enclose the TabContainer in an update panel.</p>
<p>Digging into the source code reveals that the ClientStateField property is not updated each time a tab new tab is selected.</p>
<p>To workaround this, include the following javascript into the head of the document</p>
<p><code>function ActiveTabChanged(sender, e) {<br />
sender.get_clientStateField().value = sender.saveClientState();<br />
}</code></p>
<p>and inside the TabContainer set the <code>OnClientActiveTabChanged="ActiveTabChanged"</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/04/23/tabcontrols-and-multiple-gridviews/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance of Generics SortedDictionary and Dictionary</title>
		<link>http://blog.nus.edu.sg/nexus/2009/04/16/performance-of-generics-sorteddictionary-and-dictionary/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/04/16/performance-of-generics-sorteddictionary-and-dictionary/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 04:17:03 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=96</guid>
		<description><![CDATA[Based on a Vladimir Bodurov blog post on IDictionary options &#8211; performance test &#8211; SortedList vs. SortedDictionary vs. Dictionary vs. Hashtable, it seems to indicate that SortedDictionary is slower during inserts as compared to Dictionary but faster during searching.
However during the course of my development in ASP.NET 3.5, there have been several occasions which seems [...]]]></description>
			<content:encoded><![CDATA[<p>Based on a Vladimir Bodurov blog post on <a href="http://blog.bodurov.com/Performance-SortedList-SortedDictionary-Dictionary-Hashtable" target="_blank">IDictionary options &#8211; performance test &#8211; SortedList vs. SortedDictionary vs. Dictionary vs. Hashtable</a>, it seems to indicate that SortedDictionary is slower during inserts as compared to Dictionary but faster during searching.</p>
<p>However during the course of my development in ASP.NET 3.5, there have been several occasions which seems to contradict this behaviour, perhaps it is because he is using WinForms and i&#8217;m using ASP.NET. So i took his code, did some modification for it to run several rounds and in IIS and went off from there (The source code can be found at the bottom of the page)</p>
<p>The test procedure is exactly the same as what he did, except since its only 2 i did 2 sets of 20, First doing SortedDictionary then Dictionary (Test result 1 to 20) and the second set doing Dictionary then SortedDictionary (Test result 21 to 40).</p>
<p>The averages of both set do seem to indicate negligible differences in the execution sequence.</p>
<p>The results are extremely interesting. Dictionary outperforms SortedDictionary on all counts! <strong>Memory usage, insertion time and search time are all much lower for Dictionary compared to SortedDictionary!</strong></p>
<p>Not really sure why this is so, but if i remember correctly Dictionary uses hashes, so my best guess is it is easier to search for a hash as compared to string comparison..</p>
<div id="attachment_101" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.nus.edu.sg/nexus/files/2009/04/search.gif"><img class="size-medium wp-image-101" src="http://blog.nus.edu.sg/nexus/files/2009/04/search-300x212.gif" alt="Time Taken for Search" width="300" height="212" /></a><p class="wp-caption-text">Time Taken for Search</p></div>
<div id="attachment_99" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.nus.edu.sg/nexus/files/2009/04/time.gif"><img class="size-medium wp-image-99" src="http://blog.nus.edu.sg/nexus/files/2009/04/time-300x211.gif" alt="Time Taken for Insert" width="300" height="211" /></a><p class="wp-caption-text">Time Taken for Insert</p></div>
<div id="attachment_100" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.nus.edu.sg/nexus/files/2009/04/memory.gif"><img class="size-medium wp-image-100" src="http://blog.nus.edu.sg/nexus/files/2009/04/memory-300x208.gif" alt="Memory Usage for Insert" width="300" height="208" /></a><p class="wp-caption-text">Memory Usage for Insert</p></div>
<p>The generated raw results from the web application</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr style="height: 15pt">
<td class="style1" style="width: 48pt;height: 30pt" rowspan="2" width="64" height="40">Test</td>
<td class="style2" style="width: 224pt" colspan="2" width="298">Memory</td>
<td class="style2" style="width: 198pt" colspan="2" width="263">Insert (Time taken in Ticks)</td>
<td class="style2" style="width: 205pt" colspan="2" width="273">Search (Time taken in Ticks)</td>
</tr>
<tr style="height: 15pt">
<td class="style3" style="height: 15pt" height="20">
<form action="test_cittka.aspx" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="post">SortedDictionary</form>
</td>
<td class="style3">Dictionary</td>
<td class="style3">
<form action="test_cittka.aspx" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="post">SortedDictionary</form>
</td>
<td class="style3">Dictionary</td>
<td class="style3">
<form action="test_cittka.aspx" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="post">SortedDictionary</form>
</td>
<td class="style3">Dictionary</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">1</td>
<td class="style4" align="right">53919472</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">48921833</td>
<td class="style4" align="right">13100780</td>
<td class="style4" align="right">488</td>
<td class="style4" align="right">132</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">2</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">47371977</td>
<td class="style4" align="right">12744252</td>
<td class="style4" align="right">647</td>
<td class="style4" align="right">72</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">3</td>
<td class="style4" align="right">53919468</td>
<td class="style4" align="right">53376088</td>
<td class="style4" align="right">47386173</td>
<td class="style4" align="right">12994452</td>
<td class="style4" align="right">209</td>
<td class="style4" align="right">69</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">4</td>
<td class="style4" align="right">53919340</td>
<td class="style4" align="right">53376124</td>
<td class="style4" align="right">47428627</td>
<td class="style4" align="right">15464752</td>
<td class="style4" align="right">239</td>
<td class="style4" align="right">71</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">5</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376112</td>
<td class="style4" align="right">47508765</td>
<td class="style4" align="right">13040552</td>
<td class="style4" align="right">211</td>
<td class="style4" align="right">68</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">6</td>
<td class="style4" align="right">53919644</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">48597956</td>
<td class="style4" align="right">13617493</td>
<td class="style4" align="right">216</td>
<td class="style4" align="right">71</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">7</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">49073226</td>
<td class="style4" align="right">13166390</td>
<td class="style4" align="right">404</td>
<td class="style4" align="right">71</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">8</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">48807615</td>
<td class="style4" align="right">13104169</td>
<td class="style4" align="right">229</td>
<td class="style4" align="right">69</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">9</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376088</td>
<td class="style4" align="right">48633159</td>
<td class="style4" align="right">12904931</td>
<td class="style4" align="right">278</td>
<td class="style4" align="right">89</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">10</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376088</td>
<td class="style4" align="right">49147736</td>
<td class="style4" align="right">13043290</td>
<td class="style4" align="right">243</td>
<td class="style4" align="right">72</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">11</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">48755009</td>
<td class="style4" align="right">12901049</td>
<td class="style4" align="right">221</td>
<td class="style4" align="right">68</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">12</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">48720694</td>
<td class="style4" align="right">12851970</td>
<td class="style4" align="right">216</td>
<td class="style4" align="right">65</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">13</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376088</td>
<td class="style4" align="right">48968614</td>
<td class="style4" align="right">13938456</td>
<td class="style4" align="right">278</td>
<td class="style4" align="right">76</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">14</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376124</td>
<td class="style4" align="right">47349876</td>
<td class="style4" align="right">13072479</td>
<td class="style4" align="right">232</td>
<td class="style4" align="right">69</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">15</td>
<td class="style4" align="right">53917592</td>
<td class="style4" align="right">53376112</td>
<td class="style4" align="right">47436475</td>
<td class="style4" align="right">13217946</td>
<td class="style4" align="right">374</td>
<td class="style4" align="right">263</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">16</td>
<td class="style4" align="right">53919496</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">47271521</td>
<td class="style4" align="right">12936580</td>
<td class="style4" align="right">279</td>
<td class="style4" align="right">85</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">17</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376088</td>
<td class="style4" align="right">49116031</td>
<td class="style4" align="right">14775245</td>
<td class="style4" align="right">228</td>
<td class="style4" align="right">64</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">18</td>
<td class="style4" align="right">53919496</td>
<td class="style4" align="right">53376076</td>
<td class="style4" align="right">47675434</td>
<td class="style4" align="right">13543449</td>
<td class="style4" align="right">258</td>
<td class="style4" align="right">79</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">19</td>
<td class="style4" align="right">53919496</td>
<td class="style4" align="right">53376088</td>
<td class="style4" align="right">47454095</td>
<td class="style4" align="right">13330955</td>
<td class="style4" align="right">219</td>
<td class="style4" align="right">62</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">20</td>
<td class="style4" align="right">53919484</td>
<td class="style4" align="right">53376100</td>
<td class="style4" align="right">49053229</td>
<td class="style4" align="right">12932112</td>
<td class="style4" align="right">236</td>
<td class="style4" align="right">73</td>
</tr>
<tr style="height: 15pt">
<td class="style5" style="height: 15pt" height="20">Average (Set 1)</td>
<td class="style4" align="right">53919390.6</td>
<td class="style4" align="right">53376098.8</td>
<td class="style4" align="right">48233902.25</td>
<td class="style4" align="right">13334065.1</td>
<td class="style4" align="right">285.25</td>
<td class="style4" align="right">84.4</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">21</td>
<td class="style6" style="width: 128pt" width="170" align="right">
<form action="test_cittka.aspx" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="post">53919496</form>
</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376052</td>
<td class="style6" style="width: 115pt" width="153" align="right">35231348</td>
<td class="style6" style="width: 83pt" width="110" align="right">9248780</td>
<td class="style6" style="width: 119pt" width="158" align="right">245</td>
<td class="style6" style="width: 86pt" width="115" align="right">108</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">22</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919544</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376064</td>
<td class="style6" style="width: 115pt" width="153" align="right">35237264</td>
<td class="style6" style="width: 83pt" width="110" align="right">8211268</td>
<td class="style6" style="width: 119pt" width="158" align="right">183</td>
<td class="style6" style="width: 86pt" width="115" align="right">312</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">23</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919544</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376052</td>
<td class="style6" style="width: 115pt" width="153" align="right">35354053</td>
<td class="style6" style="width: 83pt" width="110" align="right">8161178</td>
<td class="style6" style="width: 119pt" width="158" align="right">170</td>
<td class="style6" style="width: 86pt" width="115" align="right">82</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">24</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919516</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376040</td>
<td class="style6" style="width: 115pt" width="153" align="right">35166182</td>
<td class="style6" style="width: 83pt" width="110" align="right">8433640</td>
<td class="style6" style="width: 119pt" width="158" align="right">248</td>
<td class="style6" style="width: 86pt" width="115" align="right">117</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">25</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919984</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376000</td>
<td class="style6" style="width: 115pt" width="153" align="right">35340838</td>
<td class="style6" style="width: 83pt" width="110" align="right">8559027</td>
<td class="style6" style="width: 119pt" width="158" align="right">161</td>
<td class="style6" style="width: 86pt" width="115" align="right">92</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">26</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376064</td>
<td class="style6" style="width: 115pt" width="153" align="right">35446193</td>
<td class="style6" style="width: 83pt" width="110" align="right">8515937</td>
<td class="style6" style="width: 119pt" width="158" align="right">190</td>
<td class="style6" style="width: 86pt" width="115" align="right">87</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">27</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376040</td>
<td class="style6" style="width: 115pt" width="153" align="right">35425444</td>
<td class="style6" style="width: 83pt" width="110" align="right">8307412</td>
<td class="style6" style="width: 119pt" width="158" align="right">301</td>
<td class="style6" style="width: 86pt" width="115" align="right">89</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">28</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919484</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376124</td>
<td class="style6" style="width: 115pt" width="153" align="right">35207419</td>
<td class="style6" style="width: 83pt" width="110" align="right">8468252</td>
<td class="style6" style="width: 119pt" width="158" align="right">173</td>
<td class="style6" style="width: 86pt" width="115" align="right">88</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">29</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376064</td>
<td class="style6" style="width: 115pt" width="153" align="right">35275126</td>
<td class="style6" style="width: 83pt" width="110" align="right">8100160</td>
<td class="style6" style="width: 119pt" width="158" align="right">326</td>
<td class="style6" style="width: 86pt" width="115" align="right">193</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">30</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376064</td>
<td class="style6" style="width: 115pt" width="153" align="right">35484239</td>
<td class="style6" style="width: 83pt" width="110" align="right">8119661</td>
<td class="style6" style="width: 119pt" width="158" align="right">188</td>
<td class="style6" style="width: 86pt" width="115" align="right">86</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">31</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376064</td>
<td class="style6" style="width: 115pt" width="153" align="right">35604412</td>
<td class="style6" style="width: 83pt" width="110" align="right">8484580</td>
<td class="style6" style="width: 119pt" width="158" align="right">180</td>
<td class="style6" style="width: 86pt" width="115" align="right">82</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">32</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376052</td>
<td class="style6" style="width: 115pt" width="153" align="right">35550023</td>
<td class="style6" style="width: 83pt" width="110" align="right">8283421</td>
<td class="style6" style="width: 119pt" width="158" align="right">247</td>
<td class="style6" style="width: 86pt" width="115" align="right">108</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">33</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376076</td>
<td class="style6" style="width: 115pt" width="153" align="right">35213423</td>
<td class="style6" style="width: 83pt" width="110" align="right">8398157</td>
<td class="style6" style="width: 119pt" width="158" align="right">187</td>
<td class="style6" style="width: 86pt" width="115" align="right">85</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">34</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919484</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376136</td>
<td class="style6" style="width: 115pt" width="153" align="right">35264521</td>
<td class="style6" style="width: 83pt" width="110" align="right">8527381</td>
<td class="style6" style="width: 119pt" width="158" align="right">183</td>
<td class="style6" style="width: 86pt" width="115" align="right">89</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">35</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919484</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376136</td>
<td class="style6" style="width: 115pt" width="153" align="right">35383377</td>
<td class="style6" style="width: 83pt" width="110" align="right">8723896</td>
<td class="style6" style="width: 119pt" width="158" align="right">179</td>
<td class="style6" style="width: 86pt" width="115" align="right">84</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">36</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919484</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376100</td>
<td class="style6" style="width: 115pt" width="153" align="right">35232178</td>
<td class="style6" style="width: 83pt" width="110" align="right">8567521</td>
<td class="style6" style="width: 119pt" width="158" align="right">162</td>
<td class="style6" style="width: 86pt" width="115" align="right">83</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">37</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919544</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376064</td>
<td class="style6" style="width: 115pt" width="153" align="right">35054454</td>
<td class="style6" style="width: 83pt" width="110" align="right">8132677</td>
<td class="style6" style="width: 119pt" width="158" align="right">174</td>
<td class="style6" style="width: 86pt" width="115" align="right">80</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">38</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376052</td>
<td class="style6" style="width: 115pt" width="153" align="right">35188672</td>
<td class="style6" style="width: 83pt" width="110" align="right">8193882</td>
<td class="style6" style="width: 119pt" width="158" align="right">184</td>
<td class="style6" style="width: 86pt" width="115" align="right">86</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">39</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919496</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376136</td>
<td class="style6" style="width: 115pt" width="153" align="right">35265145</td>
<td class="style6" style="width: 83pt" width="110" align="right">8709565</td>
<td class="style6" style="width: 119pt" width="158" align="right">179</td>
<td class="style6" style="width: 86pt" width="115" align="right">103</td>
</tr>
<tr style="height: 15pt">
<td class="style4" style="height: 15pt" height="20" align="right">40</td>
<td class="style6" style="width: 128pt" width="170" align="right">53919532</td>
<td class="style6" style="width: 96pt" width="128" align="right">53376064</td>
<td class="style6" style="width: 115pt" width="153" align="right">35123234</td>
<td class="style6" style="width: 83pt" width="110" align="right">8095966</td>
<td class="style6" style="width: 119pt" width="158" align="right">199</td>
<td class="style6" style="width: 86pt" width="115" align="right">87</td>
</tr>
<tr style="height: 15pt">
<td class="style5" style="height: 15pt" height="20">Average (Set 2)</td>
<td class="style4" align="right">53919542.4</td>
<td class="style4" align="right">53376072.2</td>
<td class="style4" align="right">35302377.25</td>
<td class="style4" align="right">8412118.05</td>
<td class="style4" align="right">202.95</td>
<td class="style4" align="right">107.05</td>
</tr>
<tr style="height: 15pt">
<td class="style5" style="height: 15pt" height="20">Average</td>
<td class="style5" align="right">53919466.5</td>
<td class="style5" align="right">53376085.5</td>
<td class="style5" align="right">41768139.75</td>
<td class="style5" align="right">10873091.58</td>
<td class="style5" align="right">244.1</td>
<td class="style5" align="right">95.725</td>
</tr>
</tbody>
</table>
<p><span style="text-decoration: underline"><strong>Source Code (.aspx.cs)<br />
</strong></span></p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Diagnostics;<br />
using System.Data;</p>
<p>public partial class test_cittka : System.Web.UI.Page<br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
DataTable tbl = new DataTable();<br />
tbl.Columns.Add(&#8221;Memory_SortedDictionary&#8221;);<br />
tbl.Columns.Add(&#8221;Memory_Dictionary&#8221;);<br />
tbl.Columns.Add(&#8221;Insert_SortedDictionary&#8221;);<br />
tbl.Columns.Add(&#8221;Insert_Dictionary&#8221;);<br />
tbl.Columns.Add(&#8221;Search_SortedDictionary&#8221;);<br />
tbl.Columns.Add(&#8221;Search_Dictionary&#8221;);</p>
<p>for (int i = 0; i &lt; 20; i++)<br />
{<br />
DataRow row = tbl.NewRow();<br />
sortedDictionary = new SortedDictionary&lt;string, string&gt;();<br />
dictionary = new Dictionary&lt;string, string&gt;();<br />
Insert_Test(&#8221;SortedDictionary&#8221;, sortedDictionary, row, 0, 2);<br />
Insert_Test(&#8221;Dictionary&#8221;, dictionary, row, 1,3);<br />
Search_Test(&#8221;SortedDictionary&#8221;, sortedDictionary, row,4);<br />
Search_Test(&#8221;Dictionary&#8221;, dictionary,row,5);<br />
tbl.Rows.Add(row);<br />
}<br />
GridView gv = new GridView();<br />
gv.DataSource = tbl;<br />
gv.DataBind();<br />
Page.Form.Controls.Add(gv);<br />
}<br />
private readonly int searchIndex = 88888;<br />
private readonly int numberRepetition = 500000;<br />
private SortedDictionary&lt;string, string&gt; sortedDictionary = new SortedDictionary&lt;string, string&gt;();<br />
private Dictionary&lt;string, string&gt; dictionary = new Dictionary&lt;string, string&gt;();</p>
<p>private void Insert_Test(string name, IDictionary&lt;string, string&gt; dict, DataRow row, int idxMemory, int idxInsert)<br />
{<br />
Response.Write(String.Format(&#8221;&lt;br&gt;&#8212;&#8212;&#8211;Insert {0}&#8212;&#8212;&#8211;&#8221;, name));<br />
string[] letters = { &#8220;A&#8221;, &#8220;B&#8221;, &#8220;C&#8221;, &#8220;D&#8221;, &#8220;E&#8221;, &#8220;F&#8221;, &#8220;G&#8221;, &#8220;H&#8221;, &#8220;I&#8221;, &#8220;J&#8221; };<br />
long memoryStart = System.GC.GetTotalMemory(true);<br />
Stopwatch watch = new Stopwatch();<br />
watch.Start();<br />
Random rand = new Random();<br />
for (int i = 0; i &lt; numberRepetition; i++)<br />
{<br />
string key = GetRandomLetter(letters, rand, i) + &#8220;_key&#8221; + i;<br />
string value = &#8220;value&#8221; + i;</p>
<p>dict.Add(key, value);<br />
}<br />
long memoryEnd = System.GC.GetTotalMemory(true);<br />
watch.Stop();<br />
Response.Write(String.Format(&#8221;&lt;br&gt;Memory Allocated by {0} is: {1}bytes&#8221;,<br />
name, memoryEnd &#8211; memoryStart));<br />
PrintResults(watch);<br />
row[idxMemory] = (memoryEnd &#8211; memoryStart).ToString();<br />
row[idxInsert] = watch.ElapsedTicks.ToString();<br />
}<br />
private void Search_Test(string name, IDictionary&lt;string, string&gt; dict, DataRow row, int idx)<br />
{<br />
Stopwatch watch = new Stopwatch();<br />
Response.Write(String.Format(&#8221;&lt;br&gt;&#8212;&#8212;&#8211;Search {0}&#8212;&#8212;&#8211;&#8221;, name));<br />
watch.Start();<br />
Response.Write(String.Format(&#8221;&lt;br&gt;Found:{0}&#8221;, dict["A_key" + searchIndex]));<br />
watch.Stop();<br />
PrintResults(watch);<br />
row[idx] = watch.ElapsedTicks.ToString();<br />
}<br />
private void PrintResults(Stopwatch watch)<br />
{<br />
Response.Write(String.Format(&#8221;&lt;br&gt;Elapsed: {0}&#8221;, watch.Elapsed));<br />
Response.Write(String.Format(&#8221;&lt;br&gt;In milliseconds: {0}&#8221;, watch.ElapsedMilliseconds));<br />
Response.Write(String.Format(&#8221;&lt;br&gt;In timer ticks: {0}&#8221;, watch.ElapsedTicks));<br />
}<br />
private string GetRandomLetter(string[] letters, Random rand, int i)<br />
{<br />
if (i == searchIndex)<br />
{<br />
return &#8220;A&#8221;;<br />
}<br />
return letters[rand.Next(0, 10)];<br />
}<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/04/16/performance-of-generics-sorteddictionary-and-dictionary/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>HttpRunTime Cache vs Enterprise Library Cache</title>
		<link>http://blog.nus.edu.sg/nexus/2009/03/28/httpruntime-cache-vs-enterprise-library-cache/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/03/28/httpruntime-cache-vs-enterprise-library-cache/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 13:26:03 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=75</guid>
		<description><![CDATA[This post aims to highlight the differences between the cache implementation of HttpRunTime and EnterpriseLibrary




HttpRuntime.Cache
Enterprise Library Caching Block


Standard Actions


Add Item to Cache




Read Item from Cache




Update Item to Cache
 (using insert)
 (using add)


Delete Item from Cache




Flush all Items in Cache




Enumeration Actions


Enumerate all items in cache




Employ LINQ Expressions




Cache Dependencies


Cache Dependency &#8211; File




Cache Dependency &#8211; Other Cache Item

 [...]]]></description>
			<content:encoded><![CDATA[<p>This post aims to highlight the differences between the cache implementation of HttpRunTime and EnterpriseLibrary</p>
<table id="table1" border="1" width="100%">
<tbody>
<tr>
<td></td>
<td>HttpRuntime.Cache</td>
<td>Enterprise Library Caching Block</td>
</tr>
<tr>
<td colspan="3"><strong>Standard Actions</strong></td>
</tr>
<tr>
<td>Add Item to Cache</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Read Item from Cache</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Update Item to Cache</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /> (using insert)</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /> (using add)</td>
</tr>
<tr>
<td>Delete Item from Cache</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Flush all Items in Cache</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/no.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td colspan="3"><strong>Enumeration Actions</strong></td>
</tr>
<tr>
<td>Enumerate all items in cache</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/no.gif" alt="" /></td>
</tr>
<tr>
<td>Employ LINQ Expressions</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/no.gif" alt="" /></td>
</tr>
<tr>
<td colspan="3"><strong>Cache Dependencies</strong></td>
</tr>
<tr>
<td>Cache Dependency &#8211; File</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Cache Dependency &#8211; Other Cache Item</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /> (write your own extension)</td>
</tr>
<tr>
<td colspan="3"><strong>Expirations</strong></td>
</tr>
<tr>
<td>Expiration &#8211; Absolute Time</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Expiration  &#8211; Sliding Time</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Expiration &#8211; Extended Formats</p>
<p>* Extended time format</p>
<p>&#8220;&lt;Minute&gt; &lt;Hour&gt; &lt;Day of month&gt; &lt;Month&gt; &lt;Day of week&gt;&#8221;</p>
<p>* means run every period</p>
<p>Examples</p>
<p>o &#8220;* * * * *&#8221; expires every minute</p>
<p>o &#8220;5 * * * *&#8221; expire 5th minute of every hour</p>
<p>o &#8220;* 21 * * *&#8221; expire every minute of the 21st hour of every day</p>
<p>o &#8220;31 15 * * *&#8221; expire 3:31 PM every day</p>
<p>o &#8220;7 4 * * 6&#8243; expire Saturday 4:07 AM</p>
<p>o &#8220;15 21 4 7 *&#8221; expire 9:15 PM on 4 July</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/no.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td colspan="3"><strong>Others</strong></td>
</tr>
<tr>
<td>Item priority</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Run function when item is removed</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/no.gif" alt="" /></td>
</tr>
<tr>
<td>Get number of items in cache</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Limit number of items in cache</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/no.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Can use persistent Storage</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/no.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
<tr>
<td>Run function to refresh item when expires</td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/no.gif" alt="" /></td>
<td><img src="http://blog.nus.edu.sg/nexus/files/2009/03/yes.gif" alt="" /></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/03/28/httpruntime-cache-vs-enterprise-library-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET and Web Gardens</title>
		<link>http://blog.nus.edu.sg/nexus/2009/03/26/aspnet-and-web-gardens/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/03/26/aspnet-and-web-gardens/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 23:53:11 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=70</guid>
		<description><![CDATA[When you are running your ASP.NET applications inside an application pool with only 1 worker process, everything works as expected. But things usually do not go so smoothly when you run the same application inside a web garden.
What is a web garden
Simply put, a web garden is a single web server running multiple IIS processes. [...]]]></description>
			<content:encoded><![CDATA[<p>When you are running your ASP.NET applications inside an application pool with only 1 worker process, everything works as expected. But things usually do not go so smoothly when you run the same application inside a web garden.</p>
<p><strong>What is a web garden</strong></p>
<p>Simply put, a web garden is a single web server running multiple IIS processes. The good thing about this is, there are multiple process which can service your http/https calls. So if a client is holding up one process, the other processes can still continue. Also if a particular process were to hang and restart itself, your website will still continue to serve clients as the other processes are running.</p>
<p><em>Read more about Microsoft&#8217;s explanation of web garden <a href="http://technet.microsoft.com/en-us/library/cc759278.aspx" target="_blank">here</a></em></p>
<p>The article clearly states that</p>
<blockquote><p>all processes have their own copy of application state, in-process session state, caches, and static data</p></blockquote>
<p>Let us examine each one of these and see what we can do to workaround it</p>
<p><strong>Application state</strong></p>
<p><span style="text-decoration: underline"><em>Problem Statement</em></span></p>
<p>As each process has their own application state, whatever you change in one process will not be updated in another process. As this exists purely for backward compatibility with classic ASP applicationstate, Microsoft does not recommend using this alot, especially for read/write operations.</p>
<p><span style="text-decoration: underline"><em>Workaround</em></span></p>
<p>Use Cache instead of ApplicationState if you can.<br />
<strong>Cached Items </strong></p>
<p><span style="text-decoration: underline"><em>Problem Statement</em></span></p>
<p>Be it HttpRunTime.Cache or Enterprise Library Cache, the cache will not reflect latest updates inside a web garden. This is because only the worker process which updated the Cache Item will see the updated values, the other worker processes will not be notified that a change has happened and will continue using the value stored in their in memory cache.</p>
<p><span style="text-decoration: underline"><em>Workaround</em></span></p>
<p>There are a few paid solutions, and the only free one so far which is able to address this is can be found at http://enyimmemcached.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=13095 or http://www.codeproject.com/KB/aspnet/memcached_aspnet.asp</p>
<p><strong>Session state</strong></p>
<p><span style="text-decoration: underline"><em>Problem Statement</em></span></p>
<p><span style="text-decoration: underline"><em></em></span>Using web gardens, you will find that the session values gets rotated around. Again this is due to the fact that different worker process is handling your request, and each worker process has its own session state management.</p>
<p><span style="text-decoration: underline"><em>Workaround</em></span></p>
<p>Simply change the inproc to either State Server or SQL Server to store the session state outside of the worker process. Performance will degrade when using either of these 2 options, but at least you can be assured of the persistancy of the data</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/03/26/aspnet-and-web-gardens/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Custom Controls</title>
		<link>http://blog.nus.edu.sg/nexus/2009/03/25/custom-controls/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/03/25/custom-controls/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 22:14:59 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=79</guid>
		<description><![CDATA[ASP.NET makes custom controls extremely easy to write, but if you are not careful, hard to manage.
There are 2 ways to create a custom control

Writing your own HTML code
Using the controls property

Writing your own HTML code
Using your own properties, you can easily write HTML code to generate the
output
e.g consider a simple scenario where you take [...]]]></description>
			<content:encoded><![CDATA[<p>ASP.NET makes custom controls extremely easy to write, but if you are not careful, hard to manage.</p>
<p>There are 2 ways to create a custom control</p>
<ol>
<li>Writing your own HTML code</li>
<li>Using the controls property</li>
</ol>
<h2>Writing your own HTML code</h2>
<p>Using your own properties, you can easily write HTML code to generate the<br />
output</p>
<p>e.g consider a simple scenario where you take in a text and color input and<br />
render the control.</p>
<p>You can simply create a class and extend it from the WebControl base class to<br />
have the functions available to your custom control.<br />
Thereafter, just create the properties you require and use them inside the<br />
Render function. <span class="style1"><br />
Do note that you can render different output when in design mode and actual<br />
rendering, all you need is to check the DesignMode property.<br />
</span>If however you need input boxes, do take note that you need to handle the<br />
postback event and put the value back into the inputs manually.</p>
<p>public<span style="font-size: x-small"> </span><span style="font-size: x-small;color: #0000ff">class</span><span style="font-size: x-small"><br />
</span><span style="font-size: x-small;color: #2b91af">SimpleControl</span><span style="font-size: x-small"> :<br />
</span><span style="font-size: x-small;color: #2b91af">WebControl<br />
</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">public</span><span style="font-size: x-small"><br />
SimpleControl()</span></p>
<p>{</p>
<p>}</p>
<p>[<span style="font-size: x-small;color: #2b91af">BindableAttribute</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #0000ff">true</span><span style="font-size: x-small">),<br />
</span><span style="font-size: x-small;color: #2b91af">Category</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">"UI"</span><span style="font-size: x-small">),<br />
</span><span style="font-size: x-small;color: #2b91af">DefaultValue</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">""</span><span style="font-size: x-small">)]</span></p>
<p><span style="font-size: x-small;color: #0000ff">public</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">string</span><span style="font-size: x-small"> Text</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">get<br />
</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small"> obj =<br />
</span><span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ViewState[</span><span style="font-size: x-small;color: #a31515">"Text"</span><span style="font-size: x-small">];</span></p>
<p><span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"> (obj == </span><br />
<span style="font-size: x-small;color: #0000ff">null</span><span style="font-size: x-small">) </span><br />
<span style="font-size: x-small;color: #0000ff">return</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #a31515">&#8220;&#8221;</span><span style="font-size: x-small">;</span></p>
<p><span style="font-size: x-small;color: #0000ff">else</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">return</span><span style="font-size: x-small"> obj.ToString();</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">set</span><span style="font-size: x-small"> { </span><br />
<span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ViewState[</span><span style="font-size: x-small;color: #a31515">"Text"</span><span style="font-size: x-small">]<br />
= </span><span style="font-size: x-small;color: #0000ff">value</span><span style="font-size: x-small">; }</span></p>
<p>}</p>
<p>[<span style="font-size: x-small;color: #2b91af">BindableAttribute</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #0000ff">true</span><span style="font-size: x-small">),<br />
</span><span style="font-size: x-small;color: #2b91af">Category</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">"UI"</span><span style="font-size: x-small">),<br />
</span><span style="font-size: x-small;color: #2b91af">DefaultValue</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">""</span><span style="font-size: x-small">)]</span></p>
<p><span style="font-size: x-small;color: #0000ff">public</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">string</span><span style="font-size: x-small"> Color</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">get<br />
</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small"> obj =<br />
</span><span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ViewState[</span><span style="font-size: x-small;color: #a31515">"Color"</span><span style="font-size: x-small">];</span></p>
<p><span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"> (obj == </span><br />
<span style="font-size: x-small;color: #0000ff">null</span><span style="font-size: x-small">) </span><br />
<span style="font-size: x-small;color: #0000ff">return</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #a31515">&#8220;&#8221;</span><span style="font-size: x-small">;</span></p>
<p><span style="font-size: x-small;color: #0000ff">else</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">return</span><span style="font-size: x-small"> obj.ToString();</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">set</span><span style="font-size: x-small"> { </span><br />
<span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ViewState[</span><span style="font-size: x-small;color: #a31515">"Color"</span><span style="font-size: x-small">]<br />
= </span><span style="font-size: x-small;color: #0000ff">value</span><span style="font-size: x-small">; }</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">protected</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">override</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">void</span><span style="font-size: x-small"> Render(</span><span style="font-size: x-small;color: #2b91af">HtmlTextWriter</span><span style="font-size: x-small"><br />
writer)</span></p>
<p>{</p>
<p>writer.Write(<span style="font-size: x-small;color: #a31515">&#8220;&lt;font color=&#8217;&#8221;</span><span style="font-size: x-small"><br />
+ Color + </span><span style="font-size: x-small;color: #a31515">&#8220;&#8216;&gt;&#8221;</span><span style="font-size: x-small"> +<br />
Text + </span><span style="font-size: x-small;color: #a31515">&#8220;&lt;/font&gt;&#8221;</span><span style="font-size: x-small">);</span></p>
<p><span style="font-size: x-small;color: #008000">//base.Render(writer);<br />
</span></p>
<p>}</p>
<p>}</p>
<h2>Using the controls property</h2>
<p>The good thing about using the controls property is that you do not need to<br />
care about ViewState (it is handled by the individual control), Postback<br />
inputs handling (handled again by the individual control).</p>
<p>The bad thing is</p>
<ol>
<li>Have to write your own custom event handlers</li>
<li>Everything needs to be control based, you cannot emit your own html.</li>
</ol>
<p>public<span style="font-size: x-small"> </span><span style="font-size: x-small;color: #0000ff">class</span><span style="font-size: x-small"><br />
</span><span style="font-size: x-small;color: #2b91af">LabelExtendedControl</span><span style="font-size: x-small"><br />
: </span><span style="font-size: x-small;color: #2b91af">Label<br />
</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">public</span><span style="font-size: x-small"><br />
SimpleControl()</span></p>
<p>{</p>
<p>}</p>
<p>[<span style="font-size: x-small;color: #2b91af">BindableAttribute</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #0000ff">true</span><span style="font-size: x-small">),<br />
</span><span style="font-size: x-small;color: #2b91af">Category</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">"UI"</span><span style="font-size: x-small">),<br />
</span><span style="font-size: x-small;color: #2b91af">DefaultValue</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">""</span><span style="font-size: x-small">)]</span></p>
<p><span style="font-size: x-small;color: #0000ff">public</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">string</span><span style="font-size: x-small"> xText</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">get<br />
</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small"> obj =<br />
</span><span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ViewState[</span><span style="font-size: x-small;color: #a31515">"Text"</span><span style="font-size: x-small">];</span></p>
<p><span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"> (obj == </span><br />
<span style="font-size: x-small;color: #0000ff">null</span><span style="font-size: x-small">) </span><br />
<span style="font-size: x-small;color: #0000ff">return</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #a31515">&#8220;&#8221;</span><span style="font-size: x-small">;</span></p>
<p><span style="font-size: x-small;color: #0000ff">else</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">return</span><span style="font-size: x-small"> obj.ToString();</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">set</span><span style="font-size: x-small"> { </span><br />
<span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ViewState[</span><span style="font-size: x-small;color: #a31515">"Text"</span><span style="font-size: x-small">]<br />
= </span><span style="font-size: x-small;color: #0000ff">value</span><span style="font-size: x-small">; }</span></p>
<p>}</p>
<p>[<span style="font-size: x-small;color: #2b91af">BindableAttribute</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #0000ff">true</span><span style="font-size: x-small">),<br />
</span><span style="font-size: x-small;color: #2b91af">Category</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">"UI"</span><span style="font-size: x-small">),<br />
</span><span style="font-size: x-small;color: #2b91af">DefaultValue</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">""</span><span style="font-size: x-small">)]</span></p>
<p><span style="font-size: x-small;color: #0000ff">public</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">string</span><span style="font-size: x-small"> xColor</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">get<br />
</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small"> obj =<br />
</span><span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ViewState[</span><span style="font-size: x-small;color: #a31515">"Color"</span><span style="font-size: x-small">];</span></p>
<p><span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"> (obj == </span><br />
<span style="font-size: x-small;color: #0000ff">null</span><span style="font-size: x-small">) </span><br />
<span style="font-size: x-small;color: #0000ff">return</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #a31515">&#8220;&#8221;</span><span style="font-size: x-small">;</span></p>
<p><span style="font-size: x-small;color: #0000ff">else</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">return</span><span style="font-size: x-small"> obj.ToString();</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">set</span><span style="font-size: x-small"> { </span><br />
<span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ViewState[</span><span style="font-size: x-small;color: #a31515">"Color"</span><span style="font-size: x-small">]<br />
= </span><span style="font-size: x-small;color: #0000ff">value</span><span style="font-size: x-small">; }</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">protected</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">override</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">void</span><span style="font-size: x-small"> Render(</span><span style="font-size: x-small;color: #2b91af">HtmlTextWriter</span><span style="font-size: x-small"><br />
writer)</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.Text = xText;</span></p>
<p><span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">.ForeColor =<br />
System.Drawing.</span><span style="font-size: x-small;color: #2b91af">Color</span><span style="font-size: x-small">.FromKnownColor(xColor);</span></p>
<p><span style="font-size: x-small;color: #0000ff">base</span><span style="font-size: x-small">.Render(writer);</span></p>
<p>}</p>
<p>}</p>
<h2>Custom Events</h2>
<p><span style="font-size: x-small">To create your own custom events, you need<br />
to write 3 main items</span></p>
<ol> <span style="font-size: x-small"></p>
<li>A readonly object containg the event</li>
<li>A function which will call the Event</li>
<li>The actual event handler itself</li>
<p></span></ol>
<p><span style="font-size: x-small;color: #0000ff">private</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">readonly</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small"> EventCreate = </span><br />
<span style="font-size: x-small;color: #0000ff">new</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small">();</span></p>
<p><span style="font-size: x-small;color: #0000ff">protected</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">virtual</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">void</span><span style="font-size: x-small"> OnCreate(</span><span style="font-size: x-small;color: #2b91af">EventArgs</span><span style="font-size: x-small"><br />
e)</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #2b91af">EventHandler</span><span style="font-size: x-small"><br />
onCreateHandler = (</span><span style="font-size: x-small;color: #2b91af">EventHandler</span><span style="font-size: x-small">)Events[EventCreate];</span></p>
<p><span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"><br />
(onCreateHandler != </span><span style="font-size: x-small;color: #0000ff">null</span><span style="font-size: x-small">)<br />
onCreateHandler(</span><span style="font-size: x-small;color: #0000ff">this</span><span style="font-size: x-small">,<br />
e);</span></p>
<p>}</p>
<p>[<span style="font-size: x-small;color: #2b91af">Category</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">"Action"</span><span style="font-size: x-small">),</span><span style="font-size: x-small;color: #2b91af">Description</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #a31515">"Raised<br />
when a CommandEvent occurs within an item."</span><span style="font-size: x-small">)]</span></p>
<p><span style="font-size: x-small;color: #0000ff">public</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">event</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #2b91af">EventHandler</span><span style="font-size: x-small"> Create</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">add<br />
</span><span style="font-size: x-small"><br />
{</span></p>
<p>Events.AddHandler(EventCreate, <span style="font-size: x-small;color: #0000ff">value</span><span style="font-size: x-small">);</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">remove<br />
</span><span style="font-size: x-small"><br />
{</span></p>
<p>Events.RemoveHandler(EventCreate, <span style="font-size: x-small;color: #0000ff">value</span><span style="font-size: x-small">);</span></p>
<p>}</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/03/25/custom-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating Active Directory using ASP.NET 3.5</title>
		<link>http://blog.nus.edu.sg/nexus/2009/03/25/updating-active-directory-using-aspnet-35/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/03/25/updating-active-directory-using-aspnet-35/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 08:34:19 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=72</guid>
		<description><![CDATA[It is extremely easy to use ASP.NET to manage your Active Directory Users. This article shall list some of the common scenarios which is most frequently used.
Points to ensure

add the reference to System.DirectoryServices
The account running the website must have the appropriate access to the AD

Get Users in Group
List&#60;UserID_CN&#62;
result = new 
List&#60;UserID_CN&#62;();

using (var
de = getEntry())
{
object
obj = [...]]]></description>
			<content:encoded><![CDATA[<p>It is extremely easy to use ASP.NET to manage your Active Directory Users. This article shall list some of the common scenarios which is most frequently used.</p>
<p>Points to ensure</p>
<ol>
<li>add the reference to System.DirectoryServices</li>
<li>The account running the website must have the appropriate access to the AD</li>
</ol>
<h2>Get Users in Group</h2>
<p><span style="font-size: x-small;color: #2b91af">List</span><span style="font-size: x-small">&lt;</span><span style="font-size: x-small;color: #2b91af">UserID_CN</span><span style="font-size: x-small">&gt;<br />
result = </span><span style="font-size: x-small;color: #0000ff">new</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #2b91af">List</span><span style="font-size: x-small">&lt;</span><span style="font-size: x-small;color: #2b91af">UserID_CN</span><span style="font-size: x-small">&gt;();<br />
</span><span style="font-size: x-small;color: #0000ff"><br />
using</span><span style="font-size: x-small"> (</span><span style="font-size: x-small;color: #0000ff">var</span><span style="font-size: x-small"><br />
de = getEntry())<br />
{<br />
</span><span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small"><br />
obj = de.Properties[</span><span style="font-size: x-small;color: #a31515">"member"</span><span style="font-size: x-small">].Value;<br />
</span><span style="font-size: x-small;color: #0000ff"><br />
if</span><span style="font-size: x-small"> (obj </span><br />
<span style="font-size: x-small;color: #0000ff">is</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">string</span><span style="font-size: x-small">)<br />
{</span></p>
<p>result.Add(<span style="font-size: x-small;color: #0000ff">new</span><span style="font-size: x-small"><br />
</span><span style="font-size: x-small;color: #2b91af">UserID_CN</span><span style="font-size: x-small">()<br />
{</span></p>
<p>CN = obj.ToString(),<br />
ID = <span style="font-size: x-small;color: #2b91af">Regex</span><span style="font-size: x-small">.Match(obj.ToString(),<br />
</span><span style="font-size: x-small;color: #a31515">&#8220;CN=(.*?),&#8221;</span><span style="font-size: x-small">, </span><br />
<span style="font-size: x-small;color: #2b91af">RegexOptions</span><span style="font-size: x-small">.IgnoreCase).Groups[1].Value</span></p>
<p>});<br />
}<br />
<span style="font-size: x-small;color: #0000ff">else</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"> (obj </span><br />
<span style="font-size: x-small;color: #0000ff">is</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small">[])<br />
{<br />
</span><span style="font-size: x-small;color: #0000ff"><br />
foreach</span><span style="font-size: x-small"> (</span><span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small"><br />
o </span><span style="font-size: x-small;color: #0000ff">in</span><span style="font-size: x-small"> (</span><span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small">[])obj)</span></p>
<p>{<br />
result.Add(<span style="font-size: x-small;color: #0000ff">new</span><span style="font-size: x-small"><br />
</span><span style="font-size: x-small;color: #2b91af">UserID_CN</span><span style="font-size: x-small">()<br />
{</span></p>
<p>CN = o.ToString(),<br />
ID = <span style="font-size: x-small;color: #2b91af">Regex</span><span style="font-size: x-small">.Match(o.ToString(),<br />
</span><span style="font-size: x-small;color: #a31515">&#8220;CN=(.*?),&#8221;</span><span style="font-size: x-small">, </span><br />
<span style="font-size: x-small;color: #2b91af">RegexOptions</span><span style="font-size: x-small">.IgnoreCase).Groups[1].Value</span></p>
<p>});<br />
}<br />
}<br />
<span style="font-size: x-small;color: #0000ff">else</span></p>
<p>{<br />
}<br />
}<br />
result = result.OrderBy(p =&gt; p.ID).ToList();<br />
<span style="font-size: x-small;color: #0000ff"><br />
return</span><span style="font-size: x-small"> result;<br />
}</span></p>
<h2>Delete Users in Group</h2>
<p><span style="font-size: x-small;color: #0000ff">using</span><span style="font-size: x-small"> (</span><span style="font-size: x-small;color: #0000ff">var</span><span style="font-size: x-small"><br />
de = getEntry())</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">foreach</span><span style="font-size: x-small"> (</span><span style="font-size: x-small;color: #2b91af">UserID_CN</span><span style="font-size: x-small"><br />
u </span><span style="font-size: x-small;color: #0000ff">in</span><span style="font-size: x-small"> GetUsersInGroup)</span></p>
<p>{</p>
<p>de.Properties[<span style="font-size: x-small;color: #a31515">"member"</span><span style="font-size: x-small">].Remove(u.CN);</span></p>
<p>}</p>
<p>de.CommitChanges();</p>
<p>de.Close();</p>
<p>}</p>
<h2>Add Users to Group</h2>
<p>de.Properties[<span style="font-size: x-small;color: #a31515">"member"</span><span style="font-size: x-small">].Add(userDN);<br />
</span></p>
<h2>Get all properties of directory entry</h2>
<p><span style="font-size: x-small;color: #0000ff">foreach</span><span style="font-size: x-small">(</span><span style="font-size: x-small;color: #0000ff">string</span><span style="font-size: x-small"><br />
key </span><span style="font-size: x-small;color: #0000ff">in</span><span style="font-size: x-small"><br />
dirEntry.Properties.PropertyNames)</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #008000">// Each property contains a collection<br />
of its own<br />
</span></p>
<p><span style="font-size: x-small;color: #008000">// that may contain multiple values<br />
</span></p>
<p>Label1.Text += <span style="font-size: x-small;color: #a31515">&#8220;&#8211;&#8221;</span><span style="font-size: x-small"><br />
+ key + </span><span style="font-size: x-small;color: #a31515">&#8220;&#8211;&lt;br&gt;&#8221;</span><span style="font-size: x-small">;</span></p>
<p><span style="font-size: x-small;color: #0000ff">foreach</span><span style="font-size: x-small">( </span><br />
<span style="font-size: x-small;color: #0000ff">object</span><span style="font-size: x-small"> propVal </span><br />
<span style="font-size: x-small;color: #0000ff">in</span><span style="font-size: x-small"> dirEntry.Properties[key]<br />
)</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"><br />
(propVal.GetType() == </span><span style="font-size: x-small;color: #0000ff">typeof</span><span style="font-size: x-small">(System.</span><span style="font-size: x-small;color: #2b91af">Byte</span><span style="font-size: x-small">[]))</span></p>
<p>{</p>
<p>Label1.Text += <span style="font-size: x-small;color: #a31515">&#8220;(&#8221;</span><span style="font-size: x-small">;</span></p>
<p><span style="font-size: x-small;color: #0000ff">for</span><span style="font-size: x-small"> (</span><span style="font-size: x-small;color: #0000ff">int</span><span style="font-size: x-small"><br />
i=((</span><span style="font-size: x-small;color: #0000ff">byte</span><span style="font-size: x-small">[])propVal).GetLowerBound(0);i&lt;((</span><span style="font-size: x-small;color: #0000ff">byte</span><span style="font-size: x-small">[])propVal).GetUpperBound(0)+1;i++)</span></p>
<p>Label1.Text += (<span style="font-size: x-small;color: #0000ff">char</span><span style="font-size: x-small">)<br />
((</span><span style="font-size: x-small;color: #0000ff">byte</span><span style="font-size: x-small">[])propVal)[i];</span></p>
<p>Label1.Text += <span style="font-size: x-small;color: #a31515">&#8220;)&lt;br&gt;&#8221;</span><span style="font-size: x-small">;</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">else</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"><br />
(propVal.GetType().ToString() == </span><span style="font-size: x-small;color: #a31515"><br />
&#8220;System.__ComObject&#8221;</span><span style="font-size: x-small">)</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">try<br />
</span></p>
<p>{</p>
<p>Label1.Text += <span style="font-size: x-small;color: #a31515">&#8220;(&#8221;</span><span style="font-size: x-small">;</span></p>
<p><span style="font-size: x-small;color: #0000ff">long</span><span style="font-size: x-small"> val_int64 =<br />
GetInt64(dirEntry, key);</span></p>
<p><span style="font-size: x-small;color: #008000">//DateTime dt =<br />
DateTime.FromFileTime(val);<br />
</span></p>
<p><span style="font-size: x-small;color: #0000ff">try<br />
</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">if</span><span style="font-size: x-small"> (val_int64 &gt;<br />
0)</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #2b91af">DateTime</span><span style="font-size: x-small"> T =<br />
</span><span style="font-size: x-small;color: #2b91af">DateTime</span><span style="font-size: x-small">.FromFileTime(val_int64);</span></p>
<p>Label1.Text += T.ToString(<span style="font-size: x-small;color: #a31515">&#8220;dd MMM yyyy<br />
HH:mm:ss&#8221;</span><span style="font-size: x-small">) + </span><span style="font-size: x-small;color: #a31515">&#8220;)&lt;br&gt;&#8221;</span><span style="font-size: x-small">;</span></p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">else<br />
</span></p>
<p>{</p>
<p><span style="font-size: x-small;color: #0000ff">throw</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #0000ff">new</span><span style="font-size: x-small"> </span><br />
<span style="font-size: x-small;color: #2b91af">Exception</span><span style="font-size: x-small">();</span></p>
<p>}</p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">catch<br />
</span></p>
<p>{</p>
<p>Label1.Text += val_int64 + <span style="font-size: x-small;color: #a31515">&#8220;)&lt;br&gt;&#8221;</span><span style="font-size: x-small">;</span></p>
<p>}</p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">catch<br />
</span></p>
<p>{</p>
<p>Label1.Text += <span style="font-size: x-small;color: #a31515">&#8220;(&#8221;</span><span style="font-size: x-small"><br />
+ propVal + </span><span style="font-size: x-small;color: #a31515">&#8220;)&lt;br&gt;&#8221;</span><span style="font-size: x-small">;</span></p>
<p>}</p>
<p>}</p>
<p><span style="font-size: x-small;color: #0000ff">else<br />
</span></p>
<p>Label1.Text += <span style="font-size: x-small;color: #a31515">&#8220;(&#8221;</span><span style="font-size: x-small"><br />
+ propVal + </span><span style="font-size: x-small;color: #a31515">&#8220;)&lt;br&gt;&#8221;</span><span style="font-size: x-small">;</span></p>
<p>}</p>
<p>}</p>
<p>Label1.Text += <span style="font-size: x-small;color: #a31515">&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&lt;br&gt;&#8221;</span><span style="font-size: x-small">;<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/03/25/updating-active-directory-using-aspnet-35/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Application Caching</title>
		<link>http://blog.nus.edu.sg/nexus/2009/03/22/application-caching/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/03/22/application-caching/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 00:41:42 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=50</guid>
		<description><![CDATA[Introduction
ASP.NET offers several forms of caching. They are output caching, HttpRuntime.Cache and finally Enterprise Library Cache. Each of these aims to meet the requirements of different scenarios.
This article shall explore the scenarios which each of these best fit.
Output caching
There are 2 variants of output caching, you can either cache the whole page or portions of [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline"><strong>Introduction</strong></span></p>
<p>ASP.NET offers several forms of caching. They are output caching, HttpRuntime.Cache and finally Enterprise Library Cache. Each of these aims to meet the requirements of different scenarios.</p>
<p>This article shall explore the scenarios which each of these best fit.</p>
<p><strong>Output caching</strong></p>
<p>There are 2 variants of output caching, you can either cache the whole page or portions of the page (these portions must be in the form of user controls)</p>
<p><span style="color: #800080">This is commonly used when the steps to reproduce the page is huge (e.g large database calls, long file read times, huge processing requirements), but the output does not change frequently</span>, e.g a FAQ page listing all the FAQs and employing javascript for inline fuzzy search (employing different scripts for different browsers)</p>
<p>When you use output caching, the output is cached for a specific duration e.g 120 seconds and can be set to vary based on different parameters e.g querystring, browser. In the previous scenario of the FAQ page, you can use the <span style="color: #008000">VaryByCustom=&#8221;browser&#8221;</span> parameter to cache and vary the output based on different browsers.</p>
<p><em></em></p>
<p><a href="http://msdn.microsoft.com/en-us/library/h30h475z(vs.71).aspx" target="_blank">MSDN on Output Caching</a></p>
<p><strong>HttpRuntime.Cache</strong></p>
<p>HttpRuntime.Cache is used to store serializable objects in a cache for future use. This cache is more powerful compared to output caching, but using it requires more work. This is frequently used to cache the return data in business layers.</p>
<p>If you do not wish to bother about the technicalities behind this cache, you can easily add to it via the following code</p>
<blockquote><p><span style="color: #008000">HttpRuntime.Cache["key"] = value</span></p></blockquote>
<p>This will add the item to the cache with default values for all parameters. Alternatively you can look at the complete  declaration for adding an item to the cache</p>
<blockquote><p><span style="color: #008000">public Object Add(<br />
string key,<br />
Object value,<br />
CacheDependency dependencies,<br />
DateTime absoluteExpiration,<br />
TimeSpan slidingExpiration,<br />
CacheItemPriority priority,<br />
CacheItemRemovedCallback onRemoveCallback<br />
)</span></p></blockquote>
<p>This allows you to add a serializable object to the cache with</p>
<ul>
<li>Dependencies: This indicates that this cache item is dependent on another object (usually a file), so when the dependency is changed, the cache object is automatically removed from the cache.</li>
<li>Absolute Expiration: This indicates that the cache item will expire after a fixed amount of time. Once the object expires, it is removed from the cache</li>
<li>Sliding Expiration: This tells the cache to extend the cache item a fixed amount of time each time the cache item is accessed. Once this amount of time is reached and the cached item is not accessed, it will expire</li>
<li>Priority: This tells the cache the priority of the cache item. This comes into effect when the cache is full and items needs to be removed. Items with a lower priorities are removed first.</li>
<li>CacheItemRemovedCallback: This is a delegate function which is run when the item is removed from the cache, the key, value and reason for removal is sent to this function so that you can do the appropriate processing.</li>
</ul>
<p><a href="http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx" target="_blank">MSDN on HttpRuntime.Cache</a></p>
<p><strong>Enterprise Library Cache</strong></p>
<p>There are 5 main differences between this and HttpRuntime.Cache. If your needs meet any one of these points, then it is recommended that you use Enterprise Library Cache.</p>
<ol>
<li>The cache is stored independently of the web server, so even if you were to do an iisreset, the cache still remains</li>
<li>You can configure the cache to be stored in a persistent backing store e.g SQL Server</li>
<li>There can be multiple caches serving different needs in the same web application</li>
<li>You need more control over expiration policies</li>
<li>You do not need to know when the item expires, but you want to be able to reload the item if required</li>
</ol>
<p><a href="http://msdn.microsoft.com/en-us/library/dd203226.aspx" target="_blank">MSDN on Enterprise Library Caching Block</a></p>
<p><strong>Summary</strong></p>
<ol>
<li>Output caching: Used to store the page output so that ASP.NET does not need to render the content again</li>
<li>HttpRuntime.Cache: Used by your web application to store items in a cache, the items will disappear when the website is reset</li>
<li>Enterprise Library Cache: Separate cache mechanism which has its own memory and data store, is not affected by server restarts (if using persistent backing store)</li>
</ol>
<p><strong>Caveats</strong></p>
<ol>
<li>All of these caches is restricted to application domain scope, i.e you cannot share them across different application domains (e.g in web garden or multi server environment)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/03/22/application-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Advanced Grid View</title>
		<link>http://blog.nus.edu.sg/nexus/2009/02/18/aspnet-advanced-grid-view/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/02/18/aspnet-advanced-grid-view/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 01:38:48 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=65</guid>
		<description><![CDATA[ASP.NET&#8217;s GridView is great, but admittedly there are limitations to what it can do.
Some nice features which are missing include

Advanced Search
Print
Save

I&#8217;ve written an advanced gridview class which is able to perform all these

This gridview comes with the ability to

Display Create button which goes to another url when clicked
Save button to save all the records in [...]]]></description>
			<content:encoded><![CDATA[<p>ASP.NET&#8217;s GridView is great, but admittedly there are limitations to what it can do.</p>
<p>Some nice features which are missing include</p>
<ol>
<li>Advanced Search</li>
<li>Print</li>
<li>Save</li>
</ol>
<p>I&#8217;ve written an advanced gridview class which is able to perform all these</p>
<p><img src="http://blog.nus.edu.sg/nexus/files/2009/02/gv_designmode.jpg" alt="GridView Design Mode" /></p>
<p>This gridview comes with the ability to</p>
<ul>
<li>Display <strong>Create</strong> button which goes to another url when clicked</li>
<li><strong>Save</strong> button to save all the records in the Gridview (yes all the records)</li>
<li><strong>Print</strong> button to print all the records in the GridView (same as save button, but will pop up a new window to do the print)</li>
<li><strong>Advanced Search</strong> which gives you &#8220;google like&#8221; search e.g using &#8220;+&#8221; , &#8220;-&#8221;, quotation marks to mark words as one key term, OR. e.g aaa bbb &#8220;&#8221;ccc ddd&#8221;" +eee -fff OR ggg</li>
</ul>
<p>Custom properties defined in this Gridview allow you to customize the top search portion</p>
<p><img src="http://blog.nus.edu.sg/nexus/files/2009/02/gv_properties.jpg" alt="GridView Additional Properties" /></p>
<p>Click <a href="http://blog.nus.edu.sg/nexus/files/2009/02/advancedgridview.zip" target="_blank">here </a>to download the class and use it in your code</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/02/18/aspnet-advanced-grid-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance Programming with ASP.NET C#</title>
		<link>http://blog.nus.edu.sg/nexus/2009/02/16/performance-programming-with-aspnet-c/</link>
		<comments>http://blog.nus.edu.sg/nexus/2009/02/16/performance-programming-with-aspnet-c/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 05:50:09 +0000</pubDate>
		<dc:creator>cittka</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blog.nus.edu.sg/nexus/?p=51</guid>
		<description><![CDATA[It is easy to develop using ASP.NET, you can have a web application with database operations up in less than half an hour. But this ease of development comes at the expense of several performance hits.

Viewstate
Web sites are stateless by design, which means that anything you have on the page is not retained when you [...]]]></description>
			<content:encoded><![CDATA[<p>It is easy to develop using ASP.NET, you can have a web application with database operations up in less than half an hour. But this ease of development comes at the expense of several performance hits.</p>
<ol>
<li><strong>Viewstate</strong><br />
Web sites are stateless by design, which means that anything you have on the page is not retained when you submit the data. What ASP.NET tries to do is to save the state on the page so that state is retained when the page submits its data.</p>
<p>However this quickly becomes unmanageable when you have too many controls on the page, especially if you have large server controls e.g gridviews. As viewstate is stored on the page itself, a simple page with a few form elements may end up sending large amounts of data on postback, the majority of which is the viewstate itself.</p>
<p>Other than increasing page size, there is also the performance cost incurred when serializing and deserializing the viewstate.</p>
<p><strong>Solution:<br />
</strong></p>
<ul>
<li>if a page is an output page and does not do any further processing, you can disable the viewstate for the page &lt;% Page EnableViewState=&#8221;false&#8221;.</li>
<li>If the control on the page does not handle any events, is not a data-bound control or the data i constantly refreshed on postback, then you can disable the viewstate for the control</li>
<li>If all else fails, you can look into storing viewstate on the session state using <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.sessionpagestatepersister.aspx" target="_blank">SessionPageStatePersister</a> (There is a drawback because the session state may expire before the user is done with what he or she is doing on the page &#8211; think blogs, wikis etc)</li>
</ul>
</li>
<li>String concatenation &amp; comparisonHaving experience with int i = 0; i = 1 +2, you decide to go ahead and do the same for strings. string s = &#8220;aa&#8221; + &#8220;bb&#8221;This is <strong>very bad</strong> programing, simply because strings work differently from numeric primitive data types. When you do this type of string concatenation, quite a fair bit of resources are created to hold the strings and results
<p>The same can be said for case insensitive string comparison, usually you would do something like string1.toLower() == string2.toLower(). Same thing occurs, temporary space needs to be created to store the lowered strings and then do a compare.</p>
<p><strong>Solution:</strong></p>
<p><strong></strong>use stringbuilder for string concatenation functions<br />
System.Text.StringBuilder sb = new System.Text.StringBuilder();<br />
sb.Append(&#8221;aa&#8221;);<br />
sb.Append(&#8221;bb&#8221;);<br />
sb.ToString();</p>
<p>use the overloaded string compare function if you want to do case insensitive searches<br />
String.Compare (string strA, string strB, bool ignoreCase);</li>
<li>For loops with easily checked conditions perform far better than for each loops. However if the for loop condition requires a property call (e.g list.count()) then it will perform much slower, in this case get the count before the loop and assign it to a variable and in the for loop check against this variable.</li>
<li>If you have multiple exit conditions, put them when it is first possible to check and also put the one most likely to happen right on top. This reduces the amount of checks needed to exit, which can give you a performance improvement.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.nus.edu.sg/nexus/2009/02/16/performance-programming-with-aspnet-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>