<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;D0UARn4yeip7ImA9WxBbE00.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931</id><updated>2010-03-11T03:00:47.092-08:00</updated><title>Random Blurbs and things of this Nature</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.jfarrell.net/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://www.jfarrell.net/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>82</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/jfarrell/cdrx" /><feedburner:info uri="jfarrell/cdrx" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;DU4MRXoyeCp7ImA9WxBVFUk.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-5705149646768480866</id><published>2010-02-18T18:53:00.001-08:00</published><updated>2010-02-18T18:53:04.490-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-18T18:53:04.490-08:00</app:edited><title>Starting with RIA Services</title><content type="html">&lt;p&gt;I am planning to speak at The New York City Code Camp on March 6, 2010, my topic will be &lt;em&gt;Developing Rich ASP .NET Web Applications with Coolite”&lt;/em&gt;.&amp;#160; To challenge myself before this I decided to experiment with Silver Light RIA Services in creating a small Silver Light application to get the data into the database.&amp;#160; I have some initial thoughts on RIA Services being something that I played with in the past and now.&amp;#160; I felt it would be good to write a blog entry to share my thoughts on the idea and how it works, also ask some questions.&lt;/p&gt;  &lt;p&gt;So let me first state that I think RIA services is a great idea, and is a step in the right direction.&amp;#160; The reason for this is that it seems no matter what tools we create or how much we abstract the application requirements continue to increase.&amp;#160; This is because as we get better at using our tools we find ourselves able to focus more on the applications at hand, when this happens inevitably we think of bigger and better things.&amp;#160; So of course, this is a vicious cycle, as we get more time we use it to make things more complex; being a developer is fun :)&lt;/p&gt;  &lt;p&gt;If you have ever made any kind of advanced web application that leverages the principles fundamental to Web 2.0 you know that it always takes a lot of code and tends to lead to some coupling that is undesirable.&amp;#160; To counter this Microsoft is working on a new idea for its Silver Light platform that automates much of the communication between the front end application and the server.&amp;#160; Its purpose is to open the door for Silver Light to be used in Line of Business applications.&lt;/p&gt;  &lt;p&gt;RIA Services is centered around the idea of Domain Context objects, which are representations of decorated backend Domain Services classes.&amp;#160; When the application is built, Visual Studio will use its internal T4 template generation engine to generate code within the Silver Light project.&amp;#160; This code can then be used and it automatically takes care of the process of connecting to the server and getting its data via WCF RIA Data Services.&lt;/p&gt;  &lt;p&gt;Now, I cannot tell you how many times this has been attempted by someone somewhere, every month it seems a new framework comes out that promises to change the way we develop the web, never does.&amp;#160; RIA services has a lot of momentum but it is not easy to get started.&amp;#160; There are a lot of gotcha, mainly because it is still so new and has a lot of things in flux.&amp;#160; .NET 4 promises the first finalized release version integrated into the .NET framework.&lt;/p&gt;  &lt;p&gt;I earnestly look forward to some additional development in this area as I think it is very important.&amp;#160; With the, pardon me, failure, of MS Ajax Microsoft made a great move to accept JQuery as the JavaScript framework of choice for ASP .NET web apps, now we see them developing a framework to help RIA development in the sandbox approach.&amp;#160; We can hope for a better outcome for the RIA services.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-5705149646768480866?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ceIgi08Fp1yxrZd86uojlx1c69o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ceIgi08Fp1yxrZd86uojlx1c69o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ceIgi08Fp1yxrZd86uojlx1c69o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ceIgi08Fp1yxrZd86uojlx1c69o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/ZzbAXA9k-UE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/5705149646768480866/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=5705149646768480866" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5705149646768480866?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5705149646768480866?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/ZzbAXA9k-UE/starting-with-ria-services.html" title="Starting with RIA Services" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://www.jfarrell.net/2010/02/starting-with-ria-services.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUQNRXo4eip7ImA9WxBWF0o.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-4105067221294539957</id><published>2010-02-09T19:29:00.001-08:00</published><updated>2010-02-09T19:43:14.432-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-09T19:43:14.432-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Implemenation" /><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><title>Understanding Co and Contra Variance in .NET 4</title><content type="html">&lt;p&gt;Of all the features that are coming in .NET 4, perhaps the one that is the most exciting to me is Covariance and Contravariance.&amp;#160; So why does this excite me more then EF and other new features coming; cause for those of us who leverage generics and polymorphism the updates to variance are a god send. Consider the following example:&lt;/p&gt;  &lt;p&gt;This is the abstract class we are going to demonstrate against:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Vehicle
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; NumberOfWheels { get; }
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Turn(&lt;span class="kwrd"&gt;string&lt;/span&gt; direction);
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Drive()
     {
          Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Driving Vehicle&amp;quot;&lt;/span&gt;);
     }
}&lt;/pre&gt;

&lt;p&gt;We create the following concrete classes defined using the Vehicle abstract class:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Car : Vehicle
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; NumberOfWheels
     {
          get { &lt;span class="kwrd"&gt;return&lt;/span&gt; 4; }
     }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Turn(&lt;span class="kwrd"&gt;string&lt;/span&gt; direction)
     {
          Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Turning &amp;quot;&lt;/span&gt; + direction + &lt;span class="str"&gt;&amp;quot; on &amp;quot;&lt;/span&gt; + NumberOfWheels + &lt;span class="str"&gt;&amp;quot; wheels&amp;quot;&lt;/span&gt;);
     }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Drive()
     {
          Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Driving the Car&amp;quot;&lt;/span&gt;);
     }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Truck : Vehicle
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; NumberOfWheels
     {
          get { &lt;span class="kwrd"&gt;return&lt;/span&gt; 6; }
     }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Turn(&lt;span class="kwrd"&gt;string&lt;/span&gt; direction)
     {
          Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Truck is Turning &amp;quot;&lt;/span&gt; + direction + &lt;span class="str"&gt;&amp;quot; on &amp;quot;&lt;/span&gt; + NumberOfWheels + &lt;span class="str"&gt;&amp;quot; wheels&amp;quot;&lt;/span&gt;);
     }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Drive()
     {
          Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Driving the Truck&amp;quot;&lt;/span&gt;);
     }
}&lt;/pre&gt;

&lt;p&gt;Now, we will define an extension method to operate on both of these types, we can do this by operating on the abstract &lt;strong&gt;Vehicle&lt;/strong&gt; type:&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;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DriveAll(&lt;span class="kwrd"&gt;this&lt;/span&gt; IEnumerable&amp;lt;Vehicle&amp;gt; listing)
{
     &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Vehicle v &lt;span class="kwrd"&gt;in&lt;/span&gt; listing)
     {
           v.Drive();
     }
}&lt;/pre&gt;

&lt;p&gt;So given all this, you might expect this bit of code to compile in C#:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
{
     List&amp;lt;IVehicle&amp;gt; carList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;IVehicle&amp;gt;()
                                    {
                                        { &lt;span class="kwrd"&gt;new&lt;/span&gt; Car() { Name = &lt;span class="str"&gt;&amp;quot;Nissan Sentra&amp;quot;&lt;/span&gt; } },
                                        { &lt;span class="kwrd"&gt;new&lt;/span&gt; Car() { Name = &lt;span class="str"&gt;&amp;quot;Volkswagon Passat&amp;quot;&lt;/span&gt; } },
                                        { &lt;span class="kwrd"&gt;new&lt;/span&gt; Car() { Name = &lt;span class="str"&gt;&amp;quot;Toyota Camry&amp;quot;&lt;/span&gt; }}
                                    };

     carList.DriveAll();
     Console.Read();
}&lt;/pre&gt;

&lt;p&gt;You would be wrong, this code does not compile because .NET 3.5 does not support covariance and contravariance.&amp;#160; This means that .NET will ONLY analyze the outer type in this case, so &lt;strong&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/strong&gt; and not look at the inner type which would allow it to know that since &lt;strong&gt;Car&lt;/strong&gt; inherits from &lt;strong&gt;Vehicle&lt;/strong&gt; this is ok.&amp;#160; To get around this we employ a interface trick to allow us to control the inner type and “trick” .NET.&amp;#160; To do this, we first need an interface:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IVehicle
{
     &lt;span class="kwrd"&gt;int&lt;/span&gt; NumberOfWheels { get; }
     &lt;span class="kwrd"&gt;void&lt;/span&gt; Turn(&lt;span class="kwrd"&gt;string&lt;/span&gt; direction);
     &lt;span class="kwrd"&gt;void&lt;/span&gt; Drive();
}&lt;/pre&gt;

&lt;p&gt;Next we update the &lt;strong&gt;Vehicle &lt;/strong&gt;definition to implement the &lt;strong&gt;IVehicle&lt;/strong&gt; interface like such:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Vehicle : IVehicle
{
     &lt;span class="rem"&gt;// ...&lt;/span&gt;
}&lt;/pre&gt;

&lt;p&gt;By doing this we are able to constrain the inner type and control it.&amp;#160; The key thing to understand here is that the extension method is attempting to find a similar signature to attach to, with thus approach we can give it that, while still keeping the flexibility of working with all types inheriting &lt;strong&gt;Vehicle&lt;/strong&gt;.&amp;#160; This is our updated signature:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DriveAll&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt; listing) &lt;span class="kwrd"&gt;where&lt;/span&gt; T : IVehicle
{
     &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (T v &lt;span class="kwrd"&gt;in&lt;/span&gt; listing)
     {
          v.Drive();
     }
}&lt;/pre&gt;

&lt;p&gt;To understand what is happening here, we are effectively taking control over the inner type through generic constraints.&amp;#160; By doing this we are able to provide the signature that .NET 3.5 will need need to provide the extension.&amp;#160; In addition, since we are using the constraint we maintain the flexibility and requirements for the internal type.&lt;/p&gt;

&lt;p&gt;However, in .NET 4 where we have covariance and contravariance, we don't need the interface approach through a generic method.&amp;#160; The inspection of the extension method will encompass an analysis of the internal type to determine the inheritance.&amp;#160; This is already being done in 3.5 on the outer type (try using &lt;strong&gt;IEnumerable&amp;lt;T&amp;gt; &lt;/strong&gt;for &lt;strong&gt;List&amp;lt;T&amp;gt;&lt;/strong&gt;), in .NET 4 we are now having it done on the internal type as well.&lt;/p&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;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;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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-4105067221294539957?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8dBKmIKcXSvnauyKI6XwRm-jofw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8dBKmIKcXSvnauyKI6XwRm-jofw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8dBKmIKcXSvnauyKI6XwRm-jofw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8dBKmIKcXSvnauyKI6XwRm-jofw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/iFF2IQ7wFS0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/4105067221294539957/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=4105067221294539957" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/4105067221294539957?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/4105067221294539957?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/iFF2IQ7wFS0/understanding-co-and-contra-variance-in.html" title="Understanding Co and Contra Variance in .NET 4" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.jfarrell.net/2010/02/understanding-co-and-contra-variance-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYGRnY9cCp7ImA9WxBXGUo.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-5689300302444806953</id><published>2010-01-31T12:48:00.001-08:00</published><updated>2010-01-31T14:15:27.868-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-31T14:15:27.868-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Implemenation" /><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Rant" /><title>How Can Extension Methods Help You?</title><content type="html">&lt;p&gt;I am a huge proponent of extension methods in .NET (and other languages).&amp;#160; I believe they are a gateway to making complex code easier to follow and understand, also helps to maintain the object oriented paradigm that .NET is built on. They are also key to the notion of Fluent APIs which has been permeating throughout the programming space for the past year or so.&lt;/p&gt;  &lt;p&gt;The idea of a Fluent API is an API that reads very much like an English sentence and is considered a tremendous advancement in readable code.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="str"&gt;&amp;quot;500&amp;quot;&lt;/span&gt;;
&lt;span class="kwrd"&gt;int&lt;/span&gt; myValue = &lt;span class="kwrd"&gt;value&lt;/span&gt;.AsInt();&lt;/pre&gt;

&lt;p&gt;This is a sample code snippet that you see a lot in my projects as I tend to work a library I have created which contains many extension methods for formatting and parsing of values. Notice how as you read the code it flows and its concise with the parsing logic centralized.&amp;#160; Traditionally you might have seen code such as this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="str"&gt;&amp;quot;a500&amp;quot;&lt;/span&gt;;
&lt;span class="kwrd"&gt;int&lt;/span&gt; myValue = &lt;span class="kwrd"&gt;int&lt;/span&gt;.MinValue;
&lt;span class="kwrd"&gt;int&lt;/span&gt; myValue = &lt;span class="kwrd"&gt;int&lt;/span&gt;.MinValue;

&lt;span class="kwrd"&gt;int&lt;/span&gt;.TryParse(&lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;out&lt;/span&gt; myValue);
myValue = Convert.ToInt32(&lt;span class="kwrd"&gt;value&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;Using TryParse, which is a standard method common to all primitive value types in .NET, this code does not throw an exception and &lt;strong&gt;myValue&lt;/strong&gt; has a value of zero at operations end.&amp;#160; I dont like this because I would expect &lt;strong&gt;TryParse&lt;/strong&gt; to leave the value of &lt;strong&gt;myValue&lt;/strong&gt; unchanged if the parse fails, it does not.&amp;#160; As for the use of &lt;strong&gt;Convert&lt;/strong&gt; it basically emulates what would happen if you called &lt;strong&gt;int.Parse&lt;/strong&gt; on this value, it throws a FormatException.&lt;/p&gt;

&lt;p&gt;In addition to the obvious problems of repeating this code anywhere you need to parse an int from a string, I find this to be very procedural.&amp;#160; Now there is no question that all programming, no matter how hard we try is going to be at some level procedural, however, my goal is always to minimize such code and keep things as Object Oriented as possible, after all that is what OO languages are designed for and, not surprisingly, very good at.&lt;/p&gt;

&lt;p&gt;Extension methods are also exceptionally useful for custom formatting and outputting for certain types. For example, lets say you wanted to output a &lt;strong&gt;DateTime&lt;/strong&gt; object is standard notation for the United States, mm/dd/yyyy.&amp;#160; Well simply calling &lt;strong&gt;ToString(“d”)&lt;/strong&gt; easily accomplishes this. But littering your code with this code could turn into a potentially horrendous maintenance problem if your boss decides it ought to be dd/mm/yyyy (which is common in Europe), but use an extension method and your code could look like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;DateTime dt = &lt;span class="kwrd"&gt;new&lt;/span&gt; DateTime(1983, 1, 13);
Console.WriteLine(dt.AsStandardFormatString());&lt;/pre&gt;

&lt;p&gt;Using this approach you can have a standard way out outputting a DateTime, perhaps stored somewhere in a different project, that you can easily update, perhaps make culture aware, all without your application ever being the wiser.&lt;/p&gt;

&lt;p&gt;So, while Extension Methods are very useful for type conversion libraries and provides standardization out formats and outputs for types, they have another great use. Provides reusable ways to affect changes on objects, collections in particular, while maintaining a very clean interfaces and emphasizing “changes as a unit of work”.&amp;#160; I am sure someone has published something relating to the notion of change as a unit of work, but let me elaborate a little further.&lt;/p&gt;

&lt;p&gt;The idea of change as a unit of work derives from the Single Responsibility Principle and Open Closed Principle laid out by Robert Martin.&amp;#160; The idea is that everything has one responsibility and it should carry out that responsibility effectively and thoroughly, from the construction of methods to the definition of classes, they amalgamation of these constructs comprises the application and only by working together can they do such.&amp;#160; Consider the following pieces of code that comes from some code that I wrote this week for a rather complex process that I am working on at work.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var scheduleList = dayList.GroupByShiperId().ConvertToSchedule();&lt;/pre&gt;

&lt;p&gt;&lt;/p&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;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;p&gt;(For those concerned, yes I did mutate this code so that it does not reflect what was actually written).&lt;/p&gt;

&lt;p&gt;The idea here is to take a very complicated process and break it down into smaller units and then create functions to carry out those units of work.&amp;#160; Hence any changes to the information is a unit of work.&amp;#160; Easily testable and thanks to extension methods, very clean from an API standpoint. But extension methods are only a small part of this process, understanding the interfaces and classes you have available to you is critical as well as it can help you move code to where it should be.&amp;#160; The method in question could easily have been a 200 line function that would have been a nightmare for anyone to maintain.&amp;#160; Instead its five functions, all with less then 12 lines working together and producing a result.&lt;/p&gt;

&lt;p&gt;Using this approach you can be less procedural in your code and leverage the object oriented paradigm of the .NET framework and help people who will come after you understand what is happening. Thus together with good function naming, you can create similar clean reusable APIs for your projects and further leverage the concept of change as a unit of work.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-5689300302444806953?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DFUophr8GmRnLfNynUi4Ielz2fw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DFUophr8GmRnLfNynUi4Ielz2fw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DFUophr8GmRnLfNynUi4Ielz2fw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DFUophr8GmRnLfNynUi4Ielz2fw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/g_3XsGzUcSw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/5689300302444806953/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=5689300302444806953" title="8 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5689300302444806953?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5689300302444806953?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/g_3XsGzUcSw/how-can-extension-methods-help-you.html" title="How Can Extension Methods Help You?" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">8</thr:total><feedburner:origLink>http://www.jfarrell.net/2010/01/how-can-extension-methods-help-you.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMBSHc9eip7ImA9WxBQF0U.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-1900510787163897689</id><published>2010-01-17T19:14:00.001-08:00</published><updated>2010-01-17T19:14:19.962-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-17T19:14:19.962-08:00</app:edited><title>Thoughts on CodeMash 2010</title><content type="html">&lt;p&gt;As CodeMash 2010 has come to a close I would like to take some time to reflect on the conference.&amp;#160; This year was, in my opinion, not quite as good as last year but a lot of fun.&amp;#160; I think this year more people decided to really forgo the sessions and focus on the networking and social interactions that really define what CodeMash is. To me CodeMash has &lt;strong&gt;ALWAYS&lt;/strong&gt; been about the people; people that you meet and the people you get to talk to and learn from.&amp;#160; So that said, I didnt feel the sessions were quite as good as last year, so we will look forward to next year.&lt;/p&gt;  &lt;p&gt;One thing that did happen was I did my first ever open spaces sessions where I spoke on Developing for Android. Considering I decided I want to talk about it earlier in the morning and did no formal preparation, it went very well.&amp;#160; I had about 20 people around me and we just talked.&amp;#160; I explained some of the things I have discovered in developing CodeMashDroid and really perked the interest for a lot of people.&amp;#160; I really want to speak next year, but for right now I am preparing to submit my first abstract to the New York City Code Camp, which would give me a chance to really push RCM’s name for web development in the New York area.&amp;#160; But I digress. Speaking of CodeMashDroid, I was amazed at how many people had Droids at the conference. It really is nice to see that Android is making good success against ATT.&lt;/p&gt;  &lt;p&gt;I was also not the only one to develop a mobile application for Droid, as an entire company decided to get involved in the development. I also missed the emails about posting information on the app so other would know where to find it, in addition I targeted only Android 2.0+ so I limited myself to those with Droids or newer; but its good to take away lessons from such an experience.&amp;#160; I also learned about some of the shortcomings in my test methodology and emulator capabilities.&lt;/p&gt;  &lt;p&gt;Overall, CodeMash was a great experience and I look forward to the same experience next year.&amp;#160; I will be posting my pictures to Facebook later this week as well as hopefully getting time to write up a few blog entries elaborating on the topics I spoke about in my Open Spaces discussion.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-1900510787163897689?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/b2I3SNOEZvO_00GdnFIISvNStFE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/b2I3SNOEZvO_00GdnFIISvNStFE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/b2I3SNOEZvO_00GdnFIISvNStFE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/b2I3SNOEZvO_00GdnFIISvNStFE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/9PL_xNLWJVs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/1900510787163897689/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=1900510787163897689" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/1900510787163897689?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/1900510787163897689?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/9PL_xNLWJVs/thoughts-on-codemash-2010.html" title="Thoughts on CodeMash 2010" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2010/01/thoughts-on-codemash-2010.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUAHQnY5cCp7ImA9WxBQFEw.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-2374210505902970779</id><published>2010-01-13T13:22:00.001-08:00</published><updated>2010-01-13T13:22:13.828-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-13T13:22:13.828-08:00</app:edited><title>Introducing CodeMashDroid</title><content type="html">&lt;p&gt;I am pleased to announce the release of a new app in the Android app store which I have entitled &lt;strong&gt;CodeMashDroid&lt;/strong&gt;.&amp;#160; This app was developed in response to the request from the CodeMash organizers that attendees develop a solution for managing the CodeMash schedule using a REST API containing information for all conference information.&amp;#160; In addition, I had just purchased a Motorola Droid and was curious in entering the world of modern mobile development.&amp;#160; So I set out to create such an application.&lt;/p&gt;  &lt;p&gt;As I developed the application I began to think about the fact that each time I went to a conference we were always being handed a piece of paper with the schedule or people would use their laptops to look up times.&amp;#160; It seems with the prevalence of cell phones, especially in the geek community, the smart handset could be used to manage this information and be used to alert people if they are missing something.&amp;#160; Think of it as a specialized calendar, or even better based on what suggestion, allow integration with Outlook, gCal, and iCal.&amp;#160; From this feedback and train of thought the idea for a conference managing application was born.&amp;#160; CodeMashDroid is a proof of concept app for this idea, and should it prove successful the project will officially kick into gear after CodeMash when we have collected feedback.&lt;/p&gt;  &lt;p&gt;To download this app please look for it in the Android App store, it is free and we welcome any feedback as we decide on how to move forward. Please leave these comments in the AppStore feedback section, we will be monitoring this and will work the features into planning as we move forward.&amp;#160; We also welcome naming suggestions as I have no idea what I am going to call this yet :)&lt;/p&gt;  &lt;p&gt;Thanks&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-2374210505902970779?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/avZeQtLU48xDKvtZJty7IE5yvrA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/avZeQtLU48xDKvtZJty7IE5yvrA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/avZeQtLU48xDKvtZJty7IE5yvrA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/avZeQtLU48xDKvtZJty7IE5yvrA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/IZaS-st-L8U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/2374210505902970779/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=2374210505902970779" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/2374210505902970779?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/2374210505902970779?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/IZaS-st-L8U/introducing-codemashdroid.html" title="Introducing CodeMashDroid" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2010/01/introducing-codemashdroid.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UFSHk7fyp7ImA9WxBRE0Q.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-230848846486683886</id><published>2010-01-01T17:20:00.001-08:00</published><updated>2010-01-01T17:20:19.707-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-01T17:20:19.707-08:00</app:edited><title>2009 Year in Review</title><content type="html">&lt;p&gt;Its amazing how much has changed in my life this decade, even in the last year. We all know how 2009 was bad for a lot of people and at the start there was much we wondered about.&amp;#160; For me, 2009 was a year of redemption, a chance to make my mark and advance in my industry.&amp;#160; When 2008 ended I had narrowly avoided being laid off from my company, and now as we ring in 2010, I feel that I can breath easy with a fair amount of job security.&amp;#160; Many other things occurred so I thought I would publish a year in review posting for this pivotal year.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Job Questions      &lt;br /&gt;&lt;/strong&gt;As December of 2008 came around I already had a feeling that I would be included in the layoffs.&amp;#160; I hadn't really been on a billable project in quite some time and though the work I had done was valuable from a process standpoint, as a consultant it really comes down to billable hours. I steeled myself for the outcome which came to fruition.&amp;#160; But all was not lost to me, I continued to work even after I was told I didn't have to, I wanted to finish this final feature I was working on, as a token of thanks to the company that gave me my start.&amp;#160; As I started looking around I had garnered much interest from the tech community and my transition to a new company seemed assured when I caught a most fortunate break. I received a phone call from our head manager in Grand Rapids who asked me if I would like my job back.&amp;#160; I was taken aback by this and asked for some time as I was considering other offers.&amp;#160; But the more I thought about it, the more I wanted to be at RCM, I felt it was the best place to learn and grow.&lt;/p&gt;  &lt;p&gt;So I had a conversation in which I asked the reasons behind the decision to let me go, it was because they had not put me on work because of the good work I was doing to improve process.&amp;#160; I said to them that if I were to come back, I would not like it if I were simply laid off again for the same reasons, something must change.&amp;#160; And so it did.&amp;#160; From the get-go they were true to their words and through work at me and I thrived.&amp;#160; I worked on one of the biggest projects the company had that year, and it became the most successful, a testament to good planning and a well organized team.&lt;/p&gt;  &lt;p&gt;Then came another challenge, we had a client who wanted something done but only PHP could be used due to the existing technologies. This time I pulled out the skills that I had not used since converting to a .NET programmer (heavily anyway) and created a well architected easily extensible enhancement to an existing software product, this time working remotely in more of a leadership role for my potion of the project, again I thrived.&amp;#160; My boss, who had always believed in me, was thrilled, I was starting to really carve out a niche for myself.&amp;#160; Then it came, the need for someone to go to New York to work on a huge project for another division in RCM, one under the direct supervision of the RCM brass.&amp;#160; After a long interview process, I was chosen and so as I close 2009, I look back on the great breaks I had knowing full well that my positioning had a lot more to do with getting them then luck.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Preparations for Japan     &lt;br /&gt;&lt;/strong&gt;With questions about my employment swirling at the end of 2008, my Japan trip for 2010 was also placed in doubt.&amp;#160; Once the employment situation stabilized, the stability led to me beginning to take the steps to prepare for my trip to Japan.&amp;#160; The first step was to refresh my knowledge of the Japanese language through study.&amp;#160; To aid in this study I purchased Rosetta stone with levels 1, 2, &amp;amp; 3 and immediately began my training.&amp;#160; The remote work in New York helped bolster my accounts and allowed me to purchase a new camera which is something that I indicated was necessary for my trip.&amp;#160; And now, as we enter the new year I am preparing final preparations for plane tickets and ryokan, hostel, and hotel reservations following CodeMash.&amp;#160; In addition, I am preparing for the final purchase, a Netbook to help with blogging details of my journey.&amp;#160; Truly 2009, was a great year that saw me take great strides in preparing for my trip.&amp;#160; The final detail that solidified my desire to go was learning that my host brother and sister would be graduating from juugaku (middle school) and shogaku (elementary school) and thus I would be in country and able to attend a juugaku entrance ceremony, and a kookoo (high school) entrance ceremony.&amp;#160; This is very exciting.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Final Reflections     &lt;br /&gt;&lt;/strong&gt;I generally tend to think that each year should bring knowledge and new experiences from which you should grow as a person.&amp;#160; And you should be proactive in seeking these experiences and seeking new challenges to increase your knowledge.&amp;#160; I feel that in the past year I have done this and grown as a person.&amp;#160; I hope to continue to increase my experience and knowledge in 2010 by continuing to challenge myself professionally and grown from the experiences I will have in Japan.&amp;#160; Happy New Year everyone, have a happy 2010.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-230848846486683886?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hI5ssCy5oxafCCtpAXXOeZvZY_M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hI5ssCy5oxafCCtpAXXOeZvZY_M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hI5ssCy5oxafCCtpAXXOeZvZY_M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hI5ssCy5oxafCCtpAXXOeZvZY_M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/roybwwcwN90" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/230848846486683886/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=230848846486683886" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/230848846486683886?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/230848846486683886?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/roybwwcwN90/2009-year-in-review.html" title="2009 Year in Review" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2010/01/2009-year-in-review.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUAQXs-fCp7ImA9WxBTF0g.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-8751322262933692160</id><published>2009-12-13T17:30:00.001-08:00</published><updated>2009-12-13T17:30:40.554-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-13T17:30:40.554-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Mobile" /><category scheme="http://www.blogger.com/atom/ns#" term="Android" /><title>The Android Experiment</title><content type="html">&lt;p&gt;Mobile development is something that I have always wanted to try, but I never owned a smart phone and so really had no deep drive to develop mobile applications. This all changed recently when I purchased a Motorola Droid and immediately began playing with the Android OS and developing applications for various purposes; mainly for conference management.&amp;#160; I have always hated how I would go to a conference and I would receive a piece of paper of have to check a website to know what sessions happened when.&amp;#160; I set out to create an Android app to help me manage the sessions available for the &lt;a href="http://www.codemash.org"&gt;Codemash&lt;/a&gt; conference that I attend annually.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Setting up the Environment&lt;/strong&gt;    &lt;br /&gt;The first step for me is always to set up an IDE and as is the case with most non-Microsoft products and technologies, the IDE in use will be Eclipse. I am not an overly big fan of Eclipse, mostly because I have been spoiled by Visual Studio, but it is a very useful tool for developing.&amp;#160; Aside from Eclipse you will also need the Android 2.0 SDK which will provide you with the emulator necessary for testing your app.&amp;#160; I found this links helpful in walking me through the process of setting things up: &lt;a href="http://developer.android.com/guide/developing/eclipse-adt.html"&gt;http://developer.android.com/guide/developing/eclipse-adt.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Understanding Android Applications     &lt;br /&gt;&lt;/strong&gt;The first thing to understand about Android apps is they are centered around an Activity.&amp;#160; An application can have many activities of differing types.&amp;#160; In general you will use a vanilla Activity, but other activity types, such as ListActivity, are also available. The primary functions of the Activity class is the onCreate functions which you will override to perform tasks associated with the app startup.&amp;#160; Creating an Android Project in Eclipse you will see your onCreate method defined as such:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;@Override
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; onCreate(Bundle savedInstanceState)
{
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
}&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The value being passed into &lt;strong&gt;setContentView&lt;/strong&gt; is actually an integer which maps to a special class called “R” which contains mapped elements from the layout, I will elaborate more on this in the next section.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the layout
    &lt;br /&gt;&lt;/strong&gt;The layouts in Android can be defined in the program if desired but Android also supports defining the layout in XML.&amp;#160; By default, Eclipse will create a layout file called main in a directory called “layout” in a special folder called “res”.&amp;#160; Now look above at what is being passed to &lt;strong&gt;setContentView&lt;/strong&gt;.&amp;#160; A special class called R is maintained by Android which contains references to elements in the view.&amp;#160; This makes it easier to references the items in the layout.&lt;/p&gt;

&lt;p&gt;The next thing to understand is that everything that can be shown to the user or used to control the structure of the UI is a “view”.&amp;#160; TextView for example is used to show text, Button is a view which is used to represent a button, ListView which is a list of items.&amp;#160; Views can have IDs which can be added to R and allow them to be easily referenced in the code.&amp;#160; LinearLayout is also a view.&amp;#160; The important thing to remember when defining your layout in XML is &lt;strong&gt;all elements must define a layout_width and a layout_height&lt;/strong&gt;.&amp;#160; If you fail to do this, your application will crash on startup when the content view is loaded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Population of ListView
    &lt;br /&gt;&lt;/strong&gt;I want to talk about this as it caused a significant amount of pain for me when I was learning it, though looking back I am confused as to why it did, but that is normal I suppose :).&amp;#160; So the first thing to understand is if you are from the .NET world, throw what you know away since Android prefers to make the population of a List as complicated as possible.&lt;/p&gt;

&lt;p&gt;First you need to have a ListView on the page, as you might expect.&amp;#160; Next if your activity does not derive from ListActivity you will need to create an Adapter class.&amp;#160; The following is my definition for the adapter I use in my CodeMash app:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomListAdapter&amp;lt;T&amp;gt; extends BaseAdapter
{
     @Override
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; getCount()
     {
          &lt;span class="kwrd"&gt;return&lt;/span&gt; _data.size();
     }

     @Override
     &lt;span class="kwrd"&gt;public&lt;/span&gt; T getItem(&lt;span class="kwrd"&gt;int&lt;/span&gt; position)
     {
          &lt;span class="kwrd"&gt;return&lt;/span&gt; _data.get(position);
     }

     @Override
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; getItemId(&lt;span class="kwrd"&gt;int&lt;/span&gt; position)
     {
          &lt;span class="kwrd"&gt;return&lt;/span&gt; position;
     }

     @Override
     &lt;span class="kwrd"&gt;public&lt;/span&gt; View getView(&lt;span class="kwrd"&gt;int&lt;/span&gt; index, View renderer, ViewGroup parent)
     {
          TextView view = &lt;span class="kwrd"&gt;new&lt;/span&gt; TextView(&lt;span class="kwrd"&gt;this&lt;/span&gt;);
          &lt;span class="kwrd"&gt;return&lt;/span&gt; view;
     }
}&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;This example uses generics for the internal list that will be applied to the ListView, but it is not required.&amp;#160; Here are some additional things that must be added to the class to make it work.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Create a constructor that takes as parameters a reference to the Activity that is called it, a parameter to hold the list you are going to bind to the ListView, and finally a reference to the ListView that we are going to bind to.&lt;/li&gt;

  &lt;li&gt;The most important thing to do is store references to the Activity and the data internal within the class, as they will be referenced and needed throughout.&amp;#160; You must also call the &lt;strong&gt;setAdapter&lt;/strong&gt; method of the ListView reference and pass as a parameter “&lt;strong&gt;this&lt;/strong&gt;”.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You will notice that inheriting from the abstract class &lt;strong&gt;BaseAdapter&lt;/strong&gt; will require the implementation of several abstract methods: &lt;em&gt;getCount, getItem, getItemId, getView.&lt;strong&gt;&amp;#160; &lt;/strong&gt;&lt;/em&gt;Here is an explanation of these functions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;getCount()&lt;/li&gt;

  &lt;ul&gt;
    &lt;li&gt;This function is responsible for returning the size of the underlying data set&lt;/li&gt;
  &lt;/ul&gt;

  &lt;li&gt;getItem(int position)&lt;/li&gt;

  &lt;ul&gt;
    &lt;li&gt;This function is responsible for returning an object from the underlying data set at a given position&lt;/li&gt;
  &lt;/ul&gt;

  &lt;li&gt;getItemId(int position)&lt;/li&gt;

  &lt;ul&gt;
    &lt;li&gt;This function is responsible for returning an identifier for the selected object at a given position. In most of my examples I just return the position that was passed, depends on if I have a key to pass out.&lt;/li&gt;
  &lt;/ul&gt;

  &lt;li&gt;getView(int index, View renderer, ViewGroup parent)&lt;/li&gt;

  &lt;ul&gt;
    &lt;li&gt;This is the most important function in the adapter, it allows you to define the ItemRow, that is how each item in the dataset is represented in the ListView.&amp;#160; Most often you will do this programmatically, though I have been working with XML inflation and that shows promise of removing UI building code from the code, which I think helps forge good separation.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/ul&gt;

&lt;p&gt;So the basic idea with the adapter is to pass in the data, the activity, and the ListView that you intend to reference and use.&amp;#160; You then make a simple call to setAdapter and read your data from within the object creating a view to represent the object for each row in the ListView using the getView method required by the &lt;strong&gt;BaseAdapter&lt;/strong&gt; abstract class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;

  &lt;br /&gt;My general feelings toward developing on Android are a mixture of annoyance and sheer fun.&amp;#160; On the one hand it is nifty to develop applications for a mobile platform and Android has a wide assortment of features to help you.&amp;#160; On the other hand, I have never been a fan of Java as it feels like a hack next to C# and the absence of the many native syntax features in Java makes some development difficult.&amp;#160; Some of the common things seem more difficult then they should be, but that could be that coming from Silverlight and Xaml, I have a higher expectation for describing layouts through markup.&lt;/p&gt;

&lt;p&gt;Overall, I like developing in Java because of how close it is to C# and .NET, and once you get used to the way it does things like events and generics it becomes less about the language and more about the platform, which is the idea.&lt;/p&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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-8751322262933692160?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FMa7eawhF5b9vdJfY1oxn-Sl7BA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FMa7eawhF5b9vdJfY1oxn-Sl7BA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FMa7eawhF5b9vdJfY1oxn-Sl7BA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FMa7eawhF5b9vdJfY1oxn-Sl7BA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/Stqk77MjLx8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/8751322262933692160/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=8751322262933692160" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8751322262933692160?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8751322262933692160?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/Stqk77MjLx8/android-experiment.html" title="The Android Experiment" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/12/android-experiment.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ENQ3s9eCp7ImA9WxNbEEg.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-4302298287483950820</id><published>2009-11-12T08:49:00.001-08:00</published><updated>2009-11-12T10:48:12.560-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-12T10:48:12.560-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Implemenation" /><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><title>Separation of Responsibilities with MVC</title><content type="html">&lt;p&gt;Recently I have been working on a new pattern with ASP .NET MVC, based mainly on what I have learned from MVVm and other patterns.&amp;#160; That said, I dont know if I can really call this new, mainly because it really is an amalgamation of patterns working together to keep the architecture clean.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1: The Controller Architecture&lt;/strong&gt;     &lt;br /&gt;As with any system enforcement of DRY (Don't Repeat Yourself) is essential.&amp;#160; This can be achieved any number of ways, though the most common way is the abstraction of what is repeated into a separate layer, to that end we introduce the &lt;strong&gt;BaseController&lt;/strong&gt; class.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BaseController : Controller
{
     &lt;span class="kwrd"&gt;protected&lt;/span&gt; ServiceController CurrentServiceController
     {
          get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set;
     }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InitalizeServiceController()
     {
          CurrentServiceController =
               ServiceController.CreateNewServiceController();
     }
     
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DestroyServiceController()
     {
          CurrentServiceController.Dispose();
     }
}&lt;/pre&gt;

&lt;p&gt;Some things to note here.&amp;#160; This class is inheriting from &lt;strong&gt;Controller&lt;/strong&gt; which is provided by Microsoft and is the standard class which all ASP .NET MVC Controller derive from.&amp;#160; The two public methods we will get to later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Creating the Controller&lt;/strong&gt; 

  &lt;br /&gt;ASP .NET MVC has many points of extensibility, and we will take advantage of two of them, the first one is how we “build” a controller.&amp;#160; Whenever a request is made, MVC must determine which controller to instantiate based on the same found in the request (&lt;a href="http://www.yourmvcwebsite.com/Series/Edit/1"&gt;http://www.yourmvcwebsite.com/Series/Edit/1&lt;/a&gt;).&amp;#160; Once it has this it will attempt to call the action.&amp;#160; The reason we need to do this is for our data layer.&amp;#160; This is a very simple instance where the Dependency Injection pattern is used, though we are choosing to not use a DI framework such as Ninject or StructureMap because our needs are simple.&amp;#160; The goal is to set the Context reference at creation and then dispose it at release.&amp;#160; We can achieve this by using what is already available and simply leverage basic inheritance.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AnimeControllerFactory : DefaultControllerFactory
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; IController CreateController(
          RequestContext requestContext,
          &lt;span class="kwrd"&gt;string&lt;/span&gt; controllerName
     )
     {
          IController controller = &lt;span class="kwrd"&gt;base&lt;/span&gt;.
               CreateController(requestContext, controllerName);
          &lt;span class="kwrd"&gt;if&lt;/span&gt; (controller &lt;span class="kwrd"&gt;as&lt;/span&gt; BaseController != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
          {
               ((BaseController)controller).InitalizeServiceController();
          }

          &lt;span class="kwrd"&gt;return&lt;/span&gt; controller;
     }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ReleaseController(IController controller)
     {
          &lt;span class="kwrd"&gt;if&lt;/span&gt; (controller &lt;span class="kwrd"&gt;as&lt;/span&gt; BaseController != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
          {
               ((BaseController)controller).DestroyServiceController();
          }

          &lt;span class="kwrd"&gt;base&lt;/span&gt;.ReleaseController(controller);
     }
}&lt;/pre&gt;

&lt;p&gt;We could have used Reflection here to determine the type name string and then used Activator to actually get an instance, but why do that when MVC already does it for you.&amp;#160; Thus we call the overridden method, which will return to us an instance implementing &lt;strong&gt;IController&lt;/strong&gt;, from there we can do some simple casting to get to &lt;strong&gt;BaseController&lt;/strong&gt;.&amp;#160; We then call our methods which take care of the initialization process while continuing to remain unaware of what is happening.&amp;#160; This is key, if we were to simply make a call to &lt;strong&gt;new()&lt;/strong&gt; we would be coupling the two projects together, we dont want to that in our ControllerFactory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: The Data Access Layer 
    &lt;br /&gt;&lt;/strong&gt;One of my goals with this architecture was to totally separate generated entities from DTOs.&amp;#160; To that end we create a “service” layer which performs the translation of a DTO to and from a Model.&amp;#160; (Note: I tend to call my generated classes models and my DTOs entities).&amp;#160; The following in an excerpt from the &lt;strong&gt;ServiceController&lt;/strong&gt; class which acts as a “service store” for all services in the application and provides access to these services for all controllers via &lt;strong&gt;BaseController&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ServiceController : IDisposable
{
     &lt;span class="kwrd"&gt;private&lt;/span&gt; ServiceController()
     {
          CurrentEntityContext = &lt;span class="kwrd"&gt;new&lt;/span&gt; AnimeEntityContext();
     }
     
     &lt;span class="kwrd"&gt;private&lt;/span&gt; AnimeEntityContext CurrentEntityContext { get; set; }
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; ServiceController CreateNewServiceController()
     {
          &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ServiceController();
     }

     &lt;span class="preproc"&gt;#region&lt;/span&gt; Service References
     &lt;span class="kwrd"&gt;private&lt;/span&gt; SeriesService _seriesService;
     &lt;span class="kwrd"&gt;public&lt;/span&gt; SeriesService SeriesService
     {
          get
          {
               &lt;span class="kwrd"&gt;if&lt;/span&gt; (_seriesService == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                    _seriesService = ServiceFactory.
                         GetServiceReference&amp;lt;SeriesService&amp;gt;(CurrentEntityContext);

               &lt;span class="kwrd"&gt;return&lt;/span&gt; _seriesService;
          }
     }
     &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Dispose()
     {
          CurrentEntityContext.Dispose();
     }
}&lt;/pre&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;p&gt;As you can see we create a private property in this controller for the EntityContext (we are using Entity Framework for the curious).&amp;#160; To reduce the repetitive and monotonous nature of writing the code for instantiating each Service class, I created a base class &lt;strong&gt;ServiceBase&lt;/strong&gt; and then a Factory class (&lt;strong&gt;ServiceFactory&lt;/strong&gt;) which takes care, generically, of setting the underlying context for those providers.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ServiceFactory
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; T GetServiceReference&amp;lt;T&amp;gt;(AnimeEntityContext context)
          &lt;span class="kwrd"&gt;where&lt;/span&gt; T : ServiceBase, &lt;span class="kwrd"&gt;new&lt;/span&gt;()
     {
          T returnObject = &lt;span class="kwrd"&gt;new&lt;/span&gt; T();
          returnObject.SetEntityContext(context);

          &lt;span class="kwrd"&gt;return&lt;/span&gt; returnObject;
     }
}&lt;/pre&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;p&gt;&lt;strong&gt;Step 4: The Model Binder&lt;/strong&gt; 

  &lt;br /&gt;For the unaware, ASP .NET MVC permits a special type of parameter passing which analyzes a form collection and assigns properties based on name to an object of a given type. This instance is then passed to the action.&amp;#160; In a previous post, it was discussed how to do this – please visit &lt;a title="http://www.jfarrell.net/2009/10/experiments-with-asp-net-mvc-model.html" href="http://www.jfarrell.net/2009/10/experiments-with-asp-net-mvc-model.html"&gt;http://www.jfarrell.net/2009/10/experiments-with-asp-net-mvc-model.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Validation of Models&lt;/strong&gt; 

  &lt;br /&gt;One of the most monotonous tasks of any web application is validation.&amp;#160; As developers we cant always understand why users do what they do, but we do know we have to guard against it.&amp;#160; How many times have you made pages which touch the same object, thus you have to violate “DRY” and you pay for it later when something changes and you forget one of the spots.&lt;/p&gt;

&lt;p&gt;Recently one of the new ways of enforcing validation is by annotating the objects, what I mean by that is the use of attributes to describe what kind of values a property can hold.&amp;#160; You will find these in the &lt;strong&gt;System.ComponentModel.DataAnnotations&lt;/strong&gt; namespace (look for v3.5) as part of MVC 2.&amp;#160; The following is an example of decorating a class to enforce validation.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SeriesEntity : IEntity
{
     &lt;span class="rem"&gt;// simple data references&lt;/span&gt;
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; SeriesId { get; set; }

     [Required(ErrorMessage = &lt;span class="str"&gt;&amp;quot;Series name is required&amp;quot;&lt;/span&gt;)]
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
        
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsActive { get; set; }

     &lt;span class="rem"&gt;// complex data references&lt;/span&gt;
     &lt;span class="kwrd"&gt;public&lt;/span&gt; IList&amp;lt;SeasonEntity&amp;gt; Seasons { get; set; }
     
     [CollectionLength(1, ErrorMessage = &lt;span class="str"&gt;&amp;quot;At least one Genre must be selected&amp;quot;&lt;/span&gt;)]
     &lt;span class="kwrd"&gt;public&lt;/span&gt; IList&amp;lt;GenreEntity&amp;gt; Genres { get; set; }
     &lt;span class="kwrd"&gt;public&lt;/span&gt; StudioEntity Studio { get; set; }
}&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;: CollectionLength is a non-standard validation attribute&lt;/em&gt;&lt;/pre&gt;

&lt;p&gt;Validation takes place in the Model Binder, so we will return to the custom model binder from the referenced blog post. The &lt;strong&gt;OnPropertyValidating&lt;/strong&gt; method is called for each property the binder is called to bind, thus we need to have its value first, hence the previous post will explain how to accomplish this.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; OnPropertyValidating(
     ControllerContext controllerContext,
     ModelBindingContext bindingContext,
     PropertyDescriptor propertyDescriptor,
     &lt;span class="kwrd"&gt;object&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)
{
     var validationAttributes = bindingContext.Model.GetType().
          GetProperty(propertyDescriptor.Name).GetCustomAttributes(&lt;span class="kwrd"&gt;false&lt;/span&gt;).
          OfType&amp;lt;ValidationAttribute&amp;gt;();
     &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var validationAttribute &lt;span class="kwrd"&gt;in&lt;/span&gt; validationAttributes)
     {
          &lt;span class="kwrd"&gt;bool&lt;/span&gt; result = validationAttribute.IsValid(bindingContext.Model.
               GetType().GetProperty(propertyDescriptor.Name).
               GetValue(bindingContext.Model, &lt;span class="kwrd"&gt;null&lt;/span&gt;));

          &lt;span class="kwrd"&gt;if&lt;/span&gt; (!result)
          {
               bindingContext.ModelState.AddModelError(
                    propertyDescriptor.Name, validationAttribute.ErrorMessage);
               &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
          }
     }
     &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Something that I noticed working with the standard binder is that it tends ignore properties containing complex types.&amp;#160; That is if you had an array of type Genre, so Genre[], it would not bind because of &lt;strong&gt;Genre&lt;/strong&gt;.&amp;#160; If you instead made it&lt;strong&gt; int[] &lt;/strong&gt;and gave it an array of GenreId values, it would work just fine.&amp;#160; But I wanted to take things one step further and have my entity comeback mostly complete and not have extra properties just to support the binder.&amp;#160; Further, I wanted to be able to validate things, hence the reason for my custom validation attribute &lt;strong&gt;CollectionLength&lt;/strong&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;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CollectionLengthAttribute : ValidationAttribute
{
     &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MinLength = 0;
     &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MaxLength = &lt;span class="kwrd"&gt;int&lt;/span&gt;.MaxValue;

     &lt;span class="kwrd"&gt;public&lt;/span&gt; CollectionLengthAttribute(&lt;span class="kwrd"&gt;int&lt;/span&gt; minlength)
     {
          MinLength = minlength;
          MaxLength = &lt;span class="kwrd"&gt;int&lt;/span&gt;.MaxValue;
     }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; CollectionLengthAttribute(&lt;span class="kwrd"&gt;int&lt;/span&gt; minlength, &lt;span class="kwrd"&gt;int&lt;/span&gt; maxlength)
     {
          MinLength = minlength;
          MaxLength = maxlength;
     }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsValid(&lt;span class="kwrd"&gt;object&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)
     {
          &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt; != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
          {
               var collection = &lt;span class="kwrd"&gt;value&lt;/span&gt; &lt;span class="kwrd"&gt;as&lt;/span&gt; IList;
               &lt;span class="kwrd"&gt;if&lt;/span&gt; (collection != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
               {
                    &lt;span class="kwrd"&gt;return&lt;/span&gt; collection.Count &amp;gt; MinLength
                         &amp;amp;&amp;amp; collection.Count &amp;lt;= MaxLength;
               }
           }
           &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
     }
}&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; 

  &lt;br /&gt;The idea behind this pattern is separate things in a very thread safe sort of way, also to unify the context being used as well remain highly testable.&amp;#160; In addition, we want to reduce dependencies and the use of reflection.&amp;#160; Reflection is an expensive operation that we don't want to do more then we have to.&amp;#160; By using &lt;strong&gt;DefaultControllerFactory &lt;/strong&gt;we are able to rely on what already exists.&amp;#160; This action alone reduces the amount of foreign dependencies (interfaces, base classes) we need to get our code to work.&amp;#160; We have two assets that are used for this purpose &lt;strong&gt;IEntity &lt;/strong&gt;and &lt;strong&gt;BaseController.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The next piece to this is how to structure the controllers themselves and how to get the data from the DTOs to the Views in a structured way such that type safety is preserved and we refrain from duplicating as much as possible.&amp;#160; That post will follow early next week.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-4302298287483950820?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0ICACnN-yoaWklcETuku8HTFqo0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0ICACnN-yoaWklcETuku8HTFqo0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0ICACnN-yoaWklcETuku8HTFqo0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0ICACnN-yoaWklcETuku8HTFqo0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/CNlf9WSuI2U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/4302298287483950820/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=4302298287483950820" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/4302298287483950820?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/4302298287483950820?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/CNlf9WSuI2U/separation-of-responsibilities-with-mvc.html" title="Separation of Responsibilities with MVC" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/11/separation-of-responsibilities-with-mvc.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A04MSXg8fCp7ImA9WxNVGUk.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-5798667550494612466</id><published>2009-10-30T17:46:00.001-07:00</published><updated>2009-10-30T17:46:28.674-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-30T17:46:28.674-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Personal" /><title>Reflecting on my first tour of duty in New York</title><content type="html">&lt;p&gt;So as I lay here in a hotel in Queens, New York I have had a chance to reflect a little on the experience I have gained over the last few months as I worked for the client out on Long Island.&amp;#160; There were many high points and a few low points, mistakes made and successes gained.&amp;#160; All in all, I really couldn’t have asked for things to have gone better.&amp;#160; I wanted to take some time and share with you some of the the things I learned and/or experienced.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1) The virtues of planning     &lt;br /&gt;&lt;/strong&gt;As a programmer we often hear the stories about staying out late or working long hours to finish a project.&amp;#160; I can recall many people in college pulling all nighters to finish projects and the constant stream of rumors from the West Coast that programmers out there often sleep at the office.&amp;#160; I have never been a fan of such a thing and usually feel that when you find yourself in such a situation it is most often because you did not plan accordingly.&lt;/p&gt;  &lt;p&gt;With this project, I made every attempt to plan. I planned what I was going to do, I planned what I was going to concentrate and think about for the future. I thought about what I would train my colleagues on for a given day. And in the end it really paid off, I worked very little hours and accomplished a great deal.&amp;#160; The application that was built was built in accordance with known practices.&amp;#160; In fact, a colleague was sent to a Microsoft technology seminar where practices for developing an application was discussed. Upon his return he shared with us what we learned, and essentially described the application’s architecture as I had intended it.&amp;#160; This was all thanks to proper planning as well as the invaluable lessons I learned from working with a host of people at RCM.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2) Communication is vital and can be redundant     &lt;br /&gt;&lt;/strong&gt;I have always had a hard time remembering things, so I write stuff down.&amp;#160; But when I write stuff down I become too detailed and I miss stuff being said as I am writing stuff down.&amp;#160; Thus I am a person who likes to try to understand small detailed chunks and maintain a high level conceptual understanding of what I am doing.&amp;#160; I am also not someone who can understand everything via reading, I am very kinetic learner.&amp;#160; Thus sometimes I had to ask questions repeatedly to make sure I understood things, especially when it came to the sometimes complex business rules of my client.&lt;/p&gt;  &lt;p&gt;To help with this I created a great working relationship with all of the members of the team by being myself.&amp;#160; By the end, I felt like one of the members in the company, not a consultant and I was able to speak candidly around them, always maintaining who was in charge.&amp;#160; There were times I had to take charge of a situation and explain what can and cannot be done on the fly.&amp;#160; I remember once that I had to explain that adding values to a table was great but unless the application knew what the value mean’t you could not add functionality this way, at least with the architecture that was put into place.&lt;/p&gt;  &lt;p&gt;I owe this great level of communication to the high satisfaction the client has with what was produced and what they learned from this experience.&amp;#160; At the start of the project a couple people knew some .NET others had only ever done AS400 programming. By the end today, they were able to speak about various abstract concepts that they had come across in their own research or things that I had spoke about during training. And they were able to understand why I had made the decisions that I had and how to help each other continue with the design concepts already in place.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;3) Dont accept tools and frameworks blindly     &lt;br /&gt;&lt;/strong&gt;If you read and follow this blog you know that we decided to use the &lt;a href="http://www.coolite.com" target="_blank"&gt;Coolite UI framework&lt;/a&gt; for this project.&amp;#160; Coolite is an set of controls built around the ExtJS framework that is designed to help developers quickly create a rich and visually appealing websites quickly.&amp;#160; With the lack of a designer on the team this framework was very appealing and was chosen as the backbone for the application; this was all before I arrived on the scene.&lt;/p&gt;  &lt;p&gt;Initially, people were ready to go with MVC and Linq2Sql so we started down that path. But I quickly noticed that this application was going to be complicated and require an advanced architecture to support the requirements.&amp;#160; I have no doubt that such an architecture is possible in MVC and I would really loved to have done this application in MVC.&amp;#160; However, given that I have far more experience with Webforms and Coolite worked better with the event model offered by Webforms I convinced the client switch to Webforms.&amp;#160; While I also tried to convince them to move away from Linq2Sql in favor of the the &lt;a href="http://www.codeplex.com/nusoftframework" target="_blank"&gt;Kinetic Framework&lt;/a&gt;, which we have used at EIS for numerous large web projects.&lt;/p&gt;  &lt;p&gt;In the end, because the application was designed so modularly it really could support a change in ORM without a major change, but the reason that was given to me was since the client wanted to use SQL stored procedures for the operations Linq2Sql seemed the best choice to them, so I lost that argument. However, by the end I spoke with the client again about this decision, and he agreed that given the chance he would have revised his decisions and decided to use Linq in place of the stored procedures.&lt;/p&gt;  &lt;p&gt;All in all the experience was exceptionally positive for both myself and the client. The application that was created was visually appealing and rich in functionality, and all through the QA sessions very few bugs were found and no critical bugs.&amp;#160; Of course, as the application moves to the official QA team I expect that problems will be found but with the excellent communication regarding project requirements I feel that these problems will not be serious.&amp;#160; In addition, I was able to impress upon those I was training the value of not just .NET and its languages, but also the value and ability to think abstractly enough to work in a object oriented environment.&amp;#160; I look forward to my return in two weeks to assist the client with a second .NET project while the approval for phase two of the current project is decided.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-5798667550494612466?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yc9xPu38FpzlNWCVGQkkAN12FQw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yc9xPu38FpzlNWCVGQkkAN12FQw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yc9xPu38FpzlNWCVGQkkAN12FQw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yc9xPu38FpzlNWCVGQkkAN12FQw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/zV2b3AHRZC0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/5798667550494612466/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=5798667550494612466" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5798667550494612466?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5798667550494612466?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/zV2b3AHRZC0/reflecting-on-my-first-tour-of-duty-in.html" title="Reflecting on my first tour of duty in New York" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/10/reflecting-on-my-first-tour-of-duty-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQFQ3g7eSp7ImA9WxNVFU8.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-4393794698704643439</id><published>2009-10-25T20:05:00.001-07:00</published><updated>2009-10-25T20:05:12.601-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-25T20:05:12.601-07:00</app:edited><title>Experiments with ASP .NET MVC Model Binding</title><content type="html">&lt;p&gt;I am really becoming a fan of the ASP .NET MVC framework, it has a lot of flexibility and lends itself well to design patterns that I currently use.&amp;#160; I also like the emerging MVVm pattern that has really become widely used among RIA apps.&amp;#160; It functions well with MVC and SilverLight because it gives us the flexibility to use ORMs like Entity Framework and Linq2Sql without having to battle with the lost context problem.&lt;/p&gt;  &lt;p&gt;I decided this weekend to sit down with MVC and play around with a feature that I really dig: Model Binding.&amp;#160; For the uninitiated, model binding in MVC offers developers a way to specify an entity as the argument to a function and based on data sent over via the request create the object for you.&amp;#160; The out of the box binder works great and will cover the vast majority of cases.&amp;#160; I decided to take this one step further and I wanted to be able to totally bind up my proxy classes (essentially the ViewModels) without having throw away properties that were just used for this purpose and without creating an inheritance hierarchy to allow subclass proxy objects to be used for the binding, offering essentially the same thing as option 1.&amp;#160; I wanted this to all happen inside the model binder, so it would be totally transparent.&lt;/p&gt;  &lt;p&gt;My result was pretty good, but not perfect.&amp;#160; It relies on a dependency and therefore is not 100% transparent and standalone.&amp;#160; This is because of what we are doing, we need to abstract the set of the property we need, this could be done via an enforced rule that constructors for proxy entities must follow or have you entities inherit from a common interfaces to guarantee that you have such a setter.&amp;#160; I choose to go with the later and defined &lt;strong&gt;IEntity&lt;/strong&gt; as such:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IEntity
{
     &lt;span class="kwrd"&gt;int&lt;/span&gt; ID { get; set; }
     &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
}&lt;/pre&gt;

&lt;p&gt;For our example, the Name setter will not be used, but it is there because it really makes sense that an Entity should provide a name for its object.&lt;/p&gt;

&lt;p&gt;So very briefly, the view model pattern relies on the creation of entity classes which are translated from generated entities.&amp;#160; This ensures that extraneous information is not passed to the client which can happen frequently when you use generated code in an all-or-nothing scenario.&amp;#160; Furthermore, you can reuse these objects within each other and thus gain higher amounts of code reuse which usually translates to greater maintainability.&amp;#160; In this example we are going to be focusing on my &lt;strong&gt;SeriesEntity&lt;/strong&gt; class, defined as such:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SeriesEntity : IEntity
{
     &lt;span class="rem"&gt;// simple data references&lt;/span&gt;
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; SeriesId { get; set; }
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsActive { get; set; }

     &lt;span class="rem"&gt;// complex data references&lt;/span&gt;
     &lt;span class="kwrd"&gt;public&lt;/span&gt; IList&amp;lt;SeasonEntity&amp;gt; Seasons { get; set; }
     &lt;span class="kwrd"&gt;public&lt;/span&gt; IList&amp;lt;GenreEntity&amp;gt; Genres { get; set; }
     &lt;span class="kwrd"&gt;public&lt;/span&gt; StudioEntity Studio { get; set; }
     
     &lt;span class="preproc"&gt;#region&lt;/span&gt; IEntity Members
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; ID
     {
          get
          {
               &lt;span class="kwrd"&gt;return&lt;/span&gt; SeriesId;
          }
          set
          {
               SeriesId = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
          }
     }
     &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
}&lt;/pre&gt;

&lt;p&gt;The use of &lt;strong&gt;IList&lt;/strong&gt; here is crucial to the solution I am going to propose, though you could make this any collection type, with the exception of an array.&lt;/p&gt;

&lt;p&gt;One of the really neat things about MVC is that in addition to allowing you the ability to override the default binder, you can also specify a binder of a specific type, all you need to is define the binders dictionary in &lt;strong&gt;Global.asax&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Application_Start()
{
     RegisterRoutes(RouteTable.Routes);
     RegisterModelBinders(ModelBinders.Binders);
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterModelBinders(
     ModelBinderDictionary binderDictionary)
{
     binderDictionary.DefaultBinder =
          &lt;span class="kwrd"&gt;new&lt;/span&gt; Binders.AnimeModelBinder();
     binderDictionary.Add(
          &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SeriesEntity), &lt;span class="kwrd"&gt;new &lt;/span&gt;SeriesModelBinder());
}&lt;/pre&gt;

&lt;p&gt;I am showing this as an example of what you can do with the binding at a type level.&amp;#160; We will be using the the DefaultModelBinder base class, so lets start with that class, firstly it must inherit from &lt;strong&gt;DefaultModelBinder&lt;/strong&gt;.&amp;#160; This class provides a variety of virtual methods that you can override, the first one we will look at is &lt;strong&gt;BindProperty&lt;/strong&gt;, this is my implementation:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BindProperty(&lt;/pre&gt;

  &lt;pre&gt;     ControllerContext controllerContext,&lt;/pre&gt;

  &lt;pre class="alt"&gt;     ModelBindingContext bindingContext,&lt;/pre&gt;

  &lt;pre&gt;     PropertyDescriptor propertyDescriptor)&lt;/pre&gt;

  &lt;pre class="alt"&gt;{&lt;/pre&gt;

  &lt;pre&gt;     &lt;span class="rem"&gt;// need name of the property we are trying to bind&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;     var propertyName = propertyDescriptor.Name;&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;     &lt;span class="rem"&gt;// find the property on the object we are binding&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;     var property = bindingContext.Model.GetType()&lt;/pre&gt;

  &lt;pre class="alt"&gt;          .GetProperty(propertyName);&lt;/pre&gt;

  &lt;pre&gt;            &lt;/pre&gt;

  &lt;pre class="alt"&gt;     &lt;span class="kwrd"&gt;if&lt;/span&gt; (property != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre&gt;          property.SetValue(bindingContext.Model,&lt;/pre&gt;

  &lt;pre class="alt"&gt;          GetObjectValueFromProperty(property,&lt;/pre&gt;

  &lt;pre&gt;               bindingContext.ValueProvider[propertyName]),&lt;/pre&gt;

  &lt;pre class="alt"&gt;               &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The BindProperty method is called each time a new property is discovered that could potentially be binded to.&amp;#160; You can control this action by specifying &lt;strong&gt;Exclude &lt;/strong&gt;when defining the parameter list for your action, example:&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;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;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;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Create([Bind(Exclude = &lt;span class="str"&gt;&amp;quot;SeriesId,Seasons&amp;quot;&lt;/span&gt;)]SeriesEntity series)&lt;/pre&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;p&gt;&lt;/p&gt;

&lt;p&gt;Notice the use of Exclude here, which ensures that the binder will not get SeriesId and Seasons to bind.&amp;#160; While our binder can handle it not being there, the lessens the load on the binder.&lt;/p&gt;

&lt;p&gt;So lets understand the Binder, first we make a call into &lt;strong&gt;GetObjectValueFromProperty&lt;/strong&gt; function which essentially determines if we need to do anything special with the values, if we dont we make a call to &lt;strong&gt;Convert.ChangeType&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.ChangeType(result.AttemptedValue, property.PropertyType);&lt;/pre&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;p&gt;I love this method, as it calls the underlying parsing logic to convert the value from (in this case) a string to whatever I desire.&amp;#160; It will fail, of course, if the value is not as expected, but this would happen with the normal binder as well.&amp;#160; So at this point, we can handle simple one-to-one arguments for value types now.&amp;#160; Lets add a means to work with complex objects.&lt;/p&gt;

&lt;p&gt;At this point we need to introduce a dependency within our code, that is we need a way to construct our proxy entities and since these are generally custom based on the application, this is where &lt;strong&gt;IEntity&lt;/strong&gt; comes into play.&amp;#160; Thus we create a method to generate an instance of a type that, using &lt;strong&gt;IEntity&lt;/strong&gt;, we can set a value to:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; GetInstanceWithId(&lt;span class="kwrd"&gt;int&lt;/span&gt; entityId, Type type)
{
     var constructor = type.GetConstructor(&lt;span class="kwrd"&gt;new&lt;/span&gt; Type[] { });
     var &lt;span class="kwrd"&gt;value&lt;/span&gt; = constructor.Invoke(&lt;span class="kwrd"&gt;null&lt;/span&gt;);

     ((IEntity) &lt;span class="kwrd"&gt;value&lt;/span&gt;).ID = entityId;
     &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Looking at this code there is one flaw and one major area of improvement.&amp;#160; The first one is this casting is unsafe, we have no idea if we can convert the type passed to &lt;strong&gt;IEntity&lt;/strong&gt; and we are hardcoding &lt;strong&gt;IEntity&lt;/strong&gt; rather then letting it being provided.&amp;#160; This is not that big of a deal as this is not code most developers working with this binder would ever see, but it is a hard dependency.&amp;#160; The best way to check this is before we call the function, we validate the the property type CAN be cast to &lt;strong&gt;IEntity&lt;/strong&gt;, example:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; CanConvertToType(Type type, Type conversionType)
{
     var interfaces = type.GetInterfaces();
     &lt;span class="kwrd"&gt;return&lt;/span&gt; interfaces.Length &amp;gt; 0 &amp;amp;&amp;amp;
          interfaces.Select(t =&amp;gt; t.Name)
               .Contains(conversionType.Name);
}&lt;/pre&gt;

&lt;p&gt;Simply pass the type of the property and the a type reference to the type we want to check the cast for and this method will tell you, though it only works for interfaces.&lt;/p&gt;

&lt;p&gt;The final pieces to this is binding a collection of values.&amp;#160; One of the things we can do with HTML is send a comma delimited list of values from the view by naming controls with the same name.&amp;#160; This will form the basis for our collection binding.&amp;#160; The reason we use &lt;strong&gt;IList&lt;/strong&gt; for our entities is so we can perform the binding and as I came to find, creating generic arrays is something .NET does not allow.&amp;#160; So the first step is to determine if the property we are looking at IS in fact a collection, we can reuse our &lt;strong&gt;CanConvertToType&lt;/strong&gt; function and pass typeof(&lt;strong&gt;ICollection&amp;lt;&amp;gt;&lt;/strong&gt;) as the conversionType parameter. &lt;/p&gt;

&lt;p&gt;The next step is determining the actual type being held by the collection, so we can determine if we can make objects that can be stored in this collection.&amp;#160; We can make a simple call to get this information:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Type elementType = property.PropertyType.GetGenericArguments()[0];&lt;/pre&gt;

&lt;p&gt;Because this is a generic, there will always be at least one argument, and because its an &lt;strong&gt;IList&lt;/strong&gt; we know that the first argument is the contained type.&amp;#160; Once we confirm that this type can be used with &lt;strong&gt;IEntity&lt;/strong&gt; we can break apart incoming value and create the &lt;strong&gt;IList &lt;/strong&gt;reference we are going to return.&amp;#160; These two lines handle these tasks:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var valueArray = result.AttemptedValue.Split(&lt;span class="str"&gt;','&lt;/span&gt;);
var valueList = (IList)Activator.CreateInstance(
     (&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(List&amp;lt;&amp;gt;).MakeGenericType(elementType)));&lt;/pre&gt;

&lt;p&gt;This code is fairly self explanation, but to reiterate, create a string array from the values coming from the form submit, and use the Activator class to create an instance of &lt;strong&gt;List&amp;lt;&amp;gt;&lt;/strong&gt; that we then cast to an &lt;strong&gt;IList&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Finally, we iterate over the string array, and call our &lt;strong&gt;GetInstanceWithId&lt;/strong&gt; function to generate an instance of the underlying type with the ID property set via the abstraction provided by &lt;strong&gt;IEntity&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So there you have it, with some very clean reflection we can build an entire proxy entity via the custom model binder, this sets us up for validation and then actions within the controller method.&amp;#160; This also centralizes how we set the values for our objects helping with maintainability.&amp;#160; Finally, if the case arises that a totally different binder is needed for a certain type, MVC does allow type level model binding configuration which allows MVC to use a certain binder for a certain type.&amp;#160; I wonder if you can specify a interface type thus you can declare an model binder for a set of entities.&lt;/p&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;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;p&gt;I hope to add validation to this example for the next entry.&lt;/p&gt;
&lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-18f9d8896416d2fb.skydrive.live.com/embedicon.aspx/BlogFiles/AMCode.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-4393794698704643439?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MWw81QynGtE45TT7Hn_Mg1U7rDA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MWw81QynGtE45TT7Hn_Mg1U7rDA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MWw81QynGtE45TT7Hn_Mg1U7rDA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MWw81QynGtE45TT7Hn_Mg1U7rDA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/6xge9_FZOz0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/4393794698704643439/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=4393794698704643439" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/4393794698704643439?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/4393794698704643439?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/6xge9_FZOz0/experiments-with-asp-net-mvc-model.html" title="Experiments with ASP .NET MVC Model Binding" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/10/experiments-with-asp-net-mvc-model.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QGR3c9fyp7ImA9WxNWGU0.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-8030000281557993635</id><published>2009-10-18T14:28:00.001-07:00</published><updated>2009-10-18T14:28:46.967-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-18T14:28:46.967-07:00</app:edited><title>The MVVM pattern and some developer reflection</title><content type="html">&lt;p&gt;It is not uncommon in the world of web programming to see a new acronym floating around every other week.&amp;#160; I saw MVVM for the first time a few months ago, but I put off really learning what it was, I was focused on other things and since all the conversation pertained to its use with SilverLight and I was not focused on SilverLight at the time I put it on the list of things to look at.&lt;/p&gt;  &lt;p&gt;Then I attended the ASP .NET MVC FireStarter in New York city where they talked about the ViewModel pattern being used for MVC applications.&amp;#160; I immediately saw the benefits of this pattern with respect to Microsoft Entity Framework as it took the hassle out of the lost/unloaded context problem I had to circumvent whenever using the framework.&amp;#160; I was able to fully create a set of objects that translated the generated entities into classes that could be efficiently used by the View, in addition, I found added benefits from having these classes inherit from each other.&amp;#160; And since every OO programmer is continually striving for a way to reuse as much as possible without creating too much complexity, this was a win in my opinion.&lt;/p&gt;  &lt;p&gt;What I did not realize at the time was, this is the essence of the MVVM pattern that has been gaining popularity.&amp;#160; It happened recently when I was thinking about the application I am developing for the client out here in New York.&amp;#160; I realized that in fact I had architected the application to follow this pattern without even realizing it.&amp;#160; As is the case whenever you realize such a thing, you start wanting to refactor bits that you did not design according to the pattern, without taking too much time in doing so.&amp;#160; I have a number of cases that I am correcting where we are using anonymous objects where we could be using these “proxy” objects as I call them, but they really are ViewModels, I am even starting to create facades for other objects that are composites of other properties within the object.&lt;/p&gt;  &lt;p&gt;What I did was I had Linq2Sql generate a bunch of classes based on the tables we are using, each of these classes is proceeded by either a t (table) or a vw (view).&amp;#160; The ActiveRecord pattern is used to make these calls into the model, thereby creating a clean separation that allows data access calls to be refactored without changing calling code.&amp;#160; At the start, we were returning the data from these calls to the View via anonymous objects. (reasons for using this architecture where mostly due to using the &lt;a href="http://www.coolite.com" target="_blank"&gt;Coolite ExtJs ASP .NET UI Framework&lt;/a&gt;).&amp;#160; However, as we began to develop the controllers which handled the brunt of the more involved functionality, I began creating classes for use by these controllers.&amp;#160; It became almost instantly apparent that these classes could also be used in the Read calls.&amp;#160; And now, I am rewriting old code to use objects themselves.&amp;#160; The value of this was recently demonstrated when the client asked for a formatting change that required a minimal to change, but the effect was application wide.&lt;/p&gt;  &lt;p&gt;The one thing I would like to do differently next time, is make the static methods use to call into the model hang off the view model objects instead, this way there is no visible usage of the generated model classes, this is how my current personal application is setup, though it uses a service based pattern for data access, this is the recommended approach when using a context driven ORM as is the case with Linq2Sql or EF.&amp;#160; I have handled the cases in which I want to share my context across many functions (for transacted scenarios) by creating &lt;strong&gt;internal &lt;/strong&gt;functions that can accept an existing context as a parameter, though it is only visible within the assembly it is defined in, this keeps calls in the view from being able to see these functions, thereby hiding the use of a context reference entirely from the view.&lt;/p&gt;  &lt;p&gt;The idea of taking the static methods off the generated views and onto the view models themselves is that, like the service pattern, the translation is shared and not implemented all over the place.&amp;#160; This means that if you want to change a property that needs to come back, you do it in one spot.&amp;#160; For custom queries, you can still define the custom translation in a custom view model.&amp;#160; But the point is that you can better control over your translation which helps with maintenance and code cleanliness.&amp;#160; One of the ways I am doing this now is creating constructors that build the ViewModel objects for me.&amp;#160; But if I can find the time to perform this refactor, it is something I will do.&amp;#160; The other concern is that I am training other developers to develop this application, so I need to be careful changing patterns on them.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-8030000281557993635?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SHCGoW3Kp9x5cMZ8f7hi6e6kKks/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SHCGoW3Kp9x5cMZ8f7hi6e6kKks/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SHCGoW3Kp9x5cMZ8f7hi6e6kKks/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SHCGoW3Kp9x5cMZ8f7hi6e6kKks/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/qffIdF75lMA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/8030000281557993635/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=8030000281557993635" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8030000281557993635?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8030000281557993635?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/qffIdF75lMA/mvvm-pattern-and-some-developer.html" title="The MVVM pattern and some developer reflection" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/10/mvvm-pattern-and-some-developer.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0ABRn48eyp7ImA9WxNWE0w.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-1816502491161815355</id><published>2009-10-11T19:49:00.001-07:00</published><updated>2009-10-11T19:49:17.073-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-11T19:49:17.073-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Preview" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><title>Experiments with MVC 2</title><content type="html">&lt;p&gt;This weekend I once again sat down to work with my existing MVC application and see what I could find and how I could better improve the pattern and my overall understanding of the framework.&amp;#160; I found a few gotchas and came up with some tips to help improve development.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Unit Testing&lt;/strong&gt;&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;I was disappointed to find that as of right now, due to breaking changes, updated unit test project templates will be needed to use your favorite unit testing framework with MVC 2.&amp;#160; This includes my favorite MbUnit v3.&amp;#160; This does not mean that you cannot use the framework, you will just have to do the setup manually.&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;&lt;strong&gt;Validation&lt;/strong&gt;&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;One of the things that I am most excited for moving forward is the new way to define validations on the server side.&amp;#160; Using the DataAnnotations library, located curiously in the System.ComponentModel parent namespace, you can easily define many of the most common validation routines, from Required to Range.&amp;#160; This validation ties tightly in with the MVC framework&lt;/li&gt;      &lt;li&gt;One of the downsides to this, however, is that it does not generate client side validation via JavaScript.&amp;#160; Thus requests must always be validated on the server, which can be expensive for a busy site.&lt;/li&gt;      &lt;li&gt;In addition, you cannot validate complex types (objects, arrays, etc) via this method.&amp;#160; I tried with an array that was assigned via ModelBinding, and the validation routine is not even called.&amp;#160; However, based on what I read regarding .NET 4, this functionality will be available via the CustomValidator attribute.&amp;#160; I really must comment on how it is strange that you can define your own custom validation attribute, but if it is attached to a complex type, you get nothing.&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;That all aside, I am really impressed with how well this ViewModel pattern works with a deferred execution system like Entity Framework.&amp;#160; Since my EF entities never cross into the web layer, only their “dumb” proxy counterparts, the separation is really very clean and easy to maintain.&amp;#160; At this point the main problem is the distinct Contexts that are open each session, but I plan to address that next week with &lt;a href="http://ninject.org/" target="_blank"&gt;Ninject&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-1816502491161815355?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DPu2XqrdroRvlVS9yU3eLuPo0vo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DPu2XqrdroRvlVS9yU3eLuPo0vo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DPu2XqrdroRvlVS9yU3eLuPo0vo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DPu2XqrdroRvlVS9yU3eLuPo0vo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/1tC4Py6Whpw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/1816502491161815355/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=1816502491161815355" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/1816502491161815355?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/1816502491161815355?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/1tC4Py6Whpw/experiments-with-mvc-2.html" title="Experiments with MVC 2" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/10/experiments-with-mvc-2.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkAAQH4_fCp7ImA9WxNXGUs.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-1845727101109158671</id><published>2009-10-07T18:19:00.000-07:00</published><updated>2009-10-07T18:19:01.044-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-07T18:19:01.044-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><title>The MVC View Model pattern</title><content type="html">&lt;p&gt;&lt;a href="http://www.asp.net/mvc" target="_blank"&gt;Microsoft ASP .NET MVC Framework&lt;/a&gt; is Microsoft’s implementation of the popular MVC pattern which was made popular for web applications chiefly by Ruby on Rails.&amp;#160; The purpose of the framework is to give developers a choice over using ASP .NET webforms which, until the advent of the MVC framework, had been the only way to develop a web application with ASP .NET.&lt;/p&gt;  &lt;p&gt;As with any new framework, especially the web, having a pattern for doing this is essential.&amp;#160; Without a pattern developing an application that is clean and a codebase that properly leverages reusability of code in very difficult to do.&amp;#160; One of the popular patterns for MVC is the ViewModel pattern.&amp;#160; In this entry I will talk about developing an application that users this pattern and also explain why we make the decisions we do in developing the application so that we follow this pattern:&lt;/p&gt;  &lt;p&gt;In the project I developed I created a web project to house my MVC project which has the following folder structure:&lt;a href="http://lh6.ggpht.com/_McWINbq-D3o/SsvsH1XH0yI/AAAAAAAAAE0/h5z_4QAIDnY/s1600-h/image%5B5%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_McWINbq-D3o/SsvsLG0oTkI/AAAAAAAAAE4/UEEEGET8hsY/image_thumb%5B3%5D.png?imgmax=800" width="346" height="667" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see I have mutated the default project and removed the Models folder and replaced it with the ViewModels folder.&amp;#160; In this folder are the classes that I will be passing to my strongly typed views.&lt;/p&gt;  &lt;p&gt;I have created two other projects for this solution that are both class libraries: &lt;strong&gt;AM.DataAccess &lt;/strong&gt;and &lt;strong&gt;AM.Models&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;This pattern follows some of the advice that I got from &lt;a href="http://www.twitter.com/sbohlen" target="_blank"&gt;@sbohlen&lt;/a&gt; at the ASP .NET MVC Firestarter I attended on 10/3.&amp;#160; His advice was that it is ok to use an ORM like the ADO .NET Entity Framework to generate your entities but you should not pass them to the View.&amp;#160; The reason for this makes sense because the generated entities come with a lot of “extra” functionality.&amp;#160; This extra functionality is great in data access scenarios, but really do not make sense in the view.&lt;/p&gt;  &lt;p&gt;This is why the ADO .NET Entities are in their own separate project.&amp;#160; The Service classes in the DataAccess project are responsible for the translation of these generated entities to the entities that will be used by the view models.&lt;/p&gt;  &lt;p&gt;Below is an example of this translation:   &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_McWINbq-D3o/SsvsMGHbkBI/AAAAAAAAAE8/hQG-QrOHKIQ/s1600-h/image%5B20%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_McWINbq-D3o/SsvsM5i91II/AAAAAAAAAFA/HYd0UDqSP3c/image_thumb%5B12%5D.png?imgmax=800" width="478" height="248" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This is simply a query that talks to the database via the EntityContext and takes the results and makes a List of these SeriesEntity objects.&amp;#160; This list is then passed to my Controller.&amp;#160; Once the controller receives it it then creates the necessary ViewModel class to be passed to the View, this is an example of such a piece of code:   &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_McWINbq-D3o/SsvsN2WlR5I/AAAAAAAAAFE/tiao6h1_wwU/s1600-h/image%5B17%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_McWINbq-D3o/SsvsOShQ5BI/AAAAAAAAAFI/IhfdvSwpO9k/image_thumb%5B9%5D.png?imgmax=800" width="471" height="145" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The advantages of this model is the isolation of the generated entities with the entities designed for the web.&amp;#160; This can reduce the amount of data sent across the wire and decreasing load size.&amp;#160; In addition, there entities are more readily serialized into JSON results by MVC. The key thing to keep in mind is the separation of the Web from the Model layer, the two should never cross.&lt;/p&gt;  &lt;p&gt;However, a disadvantage with using the Entity Framework in this way is the management of the context object (EntityContext in the example code).&amp;#160; The way I have this setup is a lazy loaded property in a base class.&amp;#160; The base class also has a destructor which disposes of the EntityContext. It doesn’t permit the sharing of the context by the request.&amp;#160; This means you have as many EntityContext references as the number of Service instances that you have.&amp;#160; Generally the best way to handle this problem is to use something like StrucutreMap or Ninject for Dependency Injection, however, that conversation is outside the scope of this post.&lt;/p&gt;  &lt;p&gt;The main goal of this pattern is to provide a very clean and lightweight means to get data from a database and pass it to the view while maintaining type safety and leveraging code reuse.&amp;#160; For example, the ViewModel classes can inherit from each other, like such.&amp;#160; First this is the base class for all the ViewModel classes that are in use within this application:   &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_McWINbq-D3o/SsvsOojlCRI/AAAAAAAAAFM/cpO2u25-Fqs/s1600-h/image%5B24%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_McWINbq-D3o/SsvsPdEvtqI/AAAAAAAAAFQ/V3xw2VO52BY/image_thumb%5B14%5D.png?imgmax=800" width="471" height="239" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So this base class defines a couple properties that will be in use on just about every page.&amp;#160; (Side note: The validation in use here is called &lt;a href="http://www.codeplex.com/FluentValidation" target="_blank"&gt;FluentValidation&lt;/a&gt;).&amp;#160; Now lets look at the next level, the SeriesViewModel class:    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_McWINbq-D3o/SsvsQfvREPI/AAAAAAAAAFU/58c64AOFPRU/s1600-h/image%5B28%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_McWINbq-D3o/SsvsRTnRgpI/AAAAAAAAAFY/l0AhScqpQcI/image_thumb%5B16%5D.png?imgmax=800" width="419" height="190" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So this defines all the information we need for the Details view.&amp;#160; Now we can use this ViewModel and inherit from it to provide the view with additional information for say the Edit/Create view.   &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_McWINbq-D3o/SsvsRyEmVRI/AAAAAAAAAFc/yhHHG82zs9c/s1600-h/image%5B32%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_McWINbq-D3o/SsvsSpNqz2I/AAAAAAAAAFg/DmqnT4gSrck/image_thumb%5B18%5D.png?imgmax=800" width="462" height="108" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;(Note: &lt;strong&gt;CheckboxItem&lt;/strong&gt; is a custom class that I created) Notice what we have available to us now in the View.&amp;#160; We have two properties that can tie into existing MVC HtmlHelper methods to provide us with select boxes or a set of Checkboxes.&lt;/p&gt;  &lt;p&gt;In conclusion, the ViewModel pattern is a very popular pattern among MVC developers because it reduces clutter in the controller and views, which is what the essence of MVC is: reduction of code and simplification of responsibilities.&amp;#160; Furthermore, using ViewModel allows you to share and reuse code across multiple view and can truly make your View agnostic from the controller. This was one of the main weaknesses of the MVP pattern used by ASP .NET, the controller (code behind) was very tightly tied to the ASPX view.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-1845727101109158671?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pQhwoir0SMWs9GKZccUIUpixgWc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pQhwoir0SMWs9GKZccUIUpixgWc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pQhwoir0SMWs9GKZccUIUpixgWc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pQhwoir0SMWs9GKZccUIUpixgWc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/Ll6dERapAzg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/1845727101109158671/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=1845727101109158671" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/1845727101109158671?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/1845727101109158671?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/Ll6dERapAzg/mvc-view-model-pattern.html" title="The MVC View Model pattern" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/10/mvc-view-model-pattern.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEMSHs8eyp7ImA9WxNXFkw.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-5915034095062639843</id><published>2009-10-03T16:31:00.001-07:00</published><updated>2009-10-03T16:31:29.573-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-03T16:31:29.573-07:00</app:edited><title>My Trip to the New York ASP .NET MVC Firestarter</title><content type="html">&lt;p&gt;Being in New York has its many perks, one is the awesome big city an hour train ride away. This city and its surrounding area offer one of the biggest markets for technology in the world and it is no surprise that Microsoft has a tremendous presence here.&amp;#160; I was informed of this event by my colleague here in New York, Anis.&amp;#160; Upon seeing it I immediately registered, not just for its content, but also its location: At the Grand Hyatt in New York City next to Grand Central station.&amp;#160; Any excuse I can find to go into the city is a valid one in my book.&lt;/p&gt;  &lt;p&gt;I want to thank &lt;a href="http://blogs.msdn.com/peterlau/about.aspx" target="_blank"&gt;Peter Laudati&lt;/a&gt;, &lt;a href="http://unhandled-exceptions.com/blog/" target="_blank"&gt;Stephen Bohlen&lt;/a&gt;, and &lt;a href="http://girldeveloper.com/" target="_blank"&gt;Sara Chipps&lt;/a&gt; for taking the time to put on this wonderful event, while a lot of the information for me was review, it was still very helpful to get other people’s perspective on the technology as well as meet local members of the New York technology community.&lt;/p&gt;  &lt;p&gt;I really enjoyed this session because it got me into thinking mode and finally got a design pattern to click in my head for MVC, I have to thank Stephen for this as he pointed out something that I was doing which I see now is a bit of an overstep in terms of the responsibility of the control.&amp;#160; I assumed that I should use EF or L2SQL entity classes as the models that are passed to my strongly typed views.&amp;#160; Stephen pointed out that why should I pass these objects, which contain so much extra information, to the model. Make simple versions, he said, and passed those.&lt;/p&gt;  &lt;p&gt;At first I didn’t agree with this point as I thought it would lead to class clutter.&amp;#160; But as I started to think about it I realized this is already what I am doing on the project out here in New York, where we use Linq2Sql unfortunately.&amp;#160; When you look at the application the L2SQL entity &lt;strong&gt;&lt;u&gt;NEVER&lt;/u&gt;&lt;/strong&gt; leave the Model layer except as an anonymous object or as a simplified entity object (realizing this made me recognize some areas that should be refactored starting Monday).&amp;#160; By using this approach with MVC we can open the ability to &lt;strong&gt;&lt;u&gt;TRUELY&lt;/u&gt;&lt;/strong&gt; leverage the idea of the Universal Model.&amp;#160; Where a single View can be used by n controllers to display data.&lt;/p&gt;  &lt;p&gt;Think about a maintenance screen for satellite data.&amp;#160; Generally you just have a Name field and then your normal Create or Update logic.&amp;#160; You could design a Web level model class with an interface that has the desired methods on it and simply work with that in the View passing it off as necessary without ever know what you are actually working with.&amp;#160; In turn this would use just one view, and save you the headache of many satellite maintenance screens.&lt;/p&gt;  &lt;p&gt;That aside, the majority of what was discussed was review, though the conversations were interesting and I was able to get to know a few of the local technologists.&amp;#160; Thinking I may look into visiting the New York .NET User group.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-5915034095062639843?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VzLLs_0tWQ3cqfOcZukMbfWNL0s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VzLLs_0tWQ3cqfOcZukMbfWNL0s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VzLLs_0tWQ3cqfOcZukMbfWNL0s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VzLLs_0tWQ3cqfOcZukMbfWNL0s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/nJLCT_Kkla0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/5915034095062639843/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=5915034095062639843" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5915034095062639843?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5915034095062639843?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/nJLCT_Kkla0/my-trip-to-new-york-asp-net-mvc.html" title="My Trip to the New York ASP .NET MVC Firestarter" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/10/my-trip-to-new-york-asp-net-mvc.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUEQXw-eip7ImA9WxNQFEo.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-8927130915618733718</id><published>2009-09-20T12:00:00.000-07:00</published><updated>2009-09-20T12:00:00.252-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-20T12:00:00.252-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><category scheme="http://www.blogger.com/atom/ns#" term="Coolite" /><title>Understanding Coolite ComboBox Mode</title><content type="html">&lt;p&gt;This week I came across a very valuable piece of information concerning Coolite combo boxes.&amp;#160; A combobox has attribute called &lt;strong&gt;Mode&lt;/strong&gt;. What this is set to greatly affects the overall behavior of the control, and can create extra queries where you may not expect them.&amp;#160; I find that having an understanding of this attribute can help you develop more efficient pages using the Coolite ComboBox.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Default&lt;/strong&gt; – The default behavior for this control is based on how it initially receives its data.&amp;#160; If it is connected to a &lt;em&gt;Store&lt;/em&gt; of any kind, it will act according to the rules of &lt;strong&gt;Remote&lt;/strong&gt; if no store is provided it will act according to the rules of &lt;strong&gt;Local&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Remote&lt;/strong&gt; – whenever the dropdown is expanded make a query to the data store to get the latest data and bind the data according to the &lt;em&gt;DisplayField&lt;/em&gt; and&lt;em&gt; ValueField&lt;/em&gt;.&amp;#160; This is where the second query comes in.&amp;#160; Even setting &lt;em&gt;AutoLoad&lt;/em&gt; to true on the &lt;strong&gt;Store&lt;/strong&gt; will cause this to happen. Be wary of this second query, especially if the query to get the data is heavy, this could easily create a bottleneck&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Local&lt;/strong&gt; – once the data is loaded do not go out and get new data unless &lt;em&gt;load&lt;/em&gt; is called on the &lt;strong&gt;Store&lt;/strong&gt;.&amp;#160; This has the greatest chance of working with potentially stale data (depending on your model) but is also the most efficient as it allows you to control when loads happen.&amp;#160; Remember, you can easily tell your &lt;strong&gt;Store&lt;/strong&gt; to load by calling the &lt;em&gt;load()&lt;/em&gt; method on the store via JavaScript&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So what is the best approach, well as my college mentor Dr. George Nezlek used to say “it depends”. I would say for the majority of these calls you are better off explicitly defining the the &lt;strong&gt;Mode&lt;/strong&gt; as &lt;strong&gt;Local&lt;/strong&gt; and controlling the loading of the store through JavaScript and event handlers.&amp;#160; However, if the user is going to spend a lot of time on the page and the data is critical and very likely to change, &lt;strong&gt;Remote&lt;/strong&gt; may be the better option.&lt;/p&gt;  &lt;p&gt;I would assume there is a way to define poll time for the DropDown query, however, I have not explored that, but something I would look at for the later case.&lt;/p&gt;  &lt;p&gt;Hope this was helpful, I discovered this and, as usual, found no documentation from Coolite explaining this, so I thought it would be useful to talk about it here.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-8927130915618733718?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zFBxdBPmrwH7wK1i3NYL7PrZx2E/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zFBxdBPmrwH7wK1i3NYL7PrZx2E/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zFBxdBPmrwH7wK1i3NYL7PrZx2E/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zFBxdBPmrwH7wK1i3NYL7PrZx2E/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/0YDuxoy2Zmo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/8927130915618733718/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=8927130915618733718" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8927130915618733718?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8927130915618733718?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/0YDuxoy2Zmo/understanding-coolite-combobox-mode.html" title="Understanding Coolite ComboBox Mode" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/09/understanding-coolite-combobox-mode.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUEEQ3w9eip7ImA9WxNQEU8.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-6737088047280926263</id><published>2009-09-16T12:00:00.000-07:00</published><updated>2009-09-16T12:00:02.262-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-16T12:00:02.262-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><title>Experiments with RIA Services</title><content type="html">&lt;p&gt;Unfortunately I have been so busy as of late I have not had the time I would like to dedicate to exploring the .NET RIA services.&amp;#160; I have been quite impressed from what I have seen on video and heard from colleagues (one colleague is already planning to use it in an enterprise project he is writing).&lt;/p&gt;  &lt;p&gt;This weekend I decided to sit down and at least understand the mechanics of transmitting data to and from the server and how to extend existing classes to increase functionality.&amp;#160; What I found is that RIA Services have a bit of a learning curve while you get your head around the model, but once you do, it works very nicely.&amp;#160; My plan was to demonstrate basic binding with an entity generated by the Entity Framework, then move on to include a single related entity, then finally a Many to Many relationships.&amp;#160; To start I brought in 4 classes from my &lt;strong&gt;AnimeManager&lt;/strong&gt; database.&amp;#160; As expected EF picked up the Many-to-Many and hide the relational table, leaving me with the following:&lt;a href="http://lh5.ggpht.com/_McWINbq-D3o/SrBSKpjimOI/AAAAAAAAAEI/5zViYz07JCs/s1600-h/image3.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_McWINbq-D3o/SrBSL638cII/AAAAAAAAAEM/xPs5dDVtixY/image_thumb1.png?imgmax=800" width="441" height="504" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Let me state that &lt;strong&gt;THIS DOES NOT WORK!!&lt;/strong&gt;&amp;#160; The RIA services &lt;strong&gt;DO NOT&lt;/strong&gt; support a many to many relationship defined this way.&amp;#160; It took me a bit of scouring but I finally came across this blog entry which explains things: &lt;a href="http://www.silverlightshow.net/items/Creating-applications-with-.NET-RIA-Service-Part-3-Adding-DomainService-class.aspx" target="_blank"&gt;Creating Apps with RIA Services (part 3)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Essentially the key is &lt;strong&gt;HOW&lt;/strong&gt; you add the entities, because you &lt;strong&gt;WANT&lt;/strong&gt; the relational tables.&amp;#160; So in this case I deleted the existing EDMX and added this as follows:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Added &lt;strong&gt;Studios, Series, SeriesGenres&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Allowed the generation of the models &lt;/li&gt;    &lt;li&gt;Used &lt;em&gt;Update Model from Database&lt;/em&gt; to add the &lt;strong&gt;Genres&lt;/strong&gt; table &lt;/li&gt;    &lt;li&gt;Removed the generated relationship between &lt;strong&gt;Genres&lt;/strong&gt; and &lt;strong&gt;Series&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Recreated this relationship manually by relating &lt;strong&gt;Genres&lt;/strong&gt; to &lt;strong&gt;SeriesGenres&lt;/strong&gt; via this dialog&lt;a href="http://lh5.ggpht.com/_McWINbq-D3o/SrBSMhjaCqI/AAAAAAAAAEQ/e5F4LCPrL5M/s1600-h/image7.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_McWINbq-D3o/SrBSNcXBMFI/AAAAAAAAAEU/5sXgbv8579A/image_thumb3.png?imgmax=800" width="392" height="381" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;IMPORTANT!!!! THE NAME OF THE RELATIONSHIP MUST MATCH THE FOREIGN KEY NAME FROM THE DATABASE&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;After adding this you will set get an error about Association type, use &lt;strong&gt;Mapping Details&lt;/strong&gt; to ensure that this relationships maps to your Many type (SeriesGenres in this case) &lt;/li&gt;    &lt;li&gt;Build, everything should go through without fail, once it does you can proceed to the next portion, creating the domain service. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;RIA Services creates Services that handle the interaction between the underlying WCF web services and the data extracted via the model layer. To create this access the &lt;strong&gt;Add New Item &lt;/strong&gt;dialog and select &lt;em&gt;Domain Service Class&lt;/em&gt;&lt;a href="http://lh4.ggpht.com/_McWINbq-D3o/SrBSO3fkIlI/AAAAAAAAAEY/BL0AEO7ERnk/s1600-h/image11.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_McWINbq-D3o/SrBSQm7f8RI/AAAAAAAAAEc/oEiSdvQto6M/image_thumb5.png?imgmax=800" width="465" height="289" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The following dialog is subsequently displayed:&lt;a href="http://lh3.ggpht.com/_McWINbq-D3o/SrBSRvKURFI/AAAAAAAAAEg/kwD1W63-Mc4/s1600-h/image19.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_McWINbq-D3o/SrBSSRn4L8I/AAAAAAAAAEk/lRnPXdD4C9E/image_thumb9.png?imgmax=800" width="303" height="397" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;A service class can support multiple entities, though convention generally dictates that each service represent one entity.&amp;#160; For the sake of this I am going to have all three, you will see why in a moment, it has to do with the&lt;strong&gt; many to many relationship.&lt;/strong&gt;&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;The important thing here is that you click &amp;quot;”Generate associated classes for metadata”.&lt;/p&gt;  &lt;p&gt;Following this screen VS will update your solution and add two files: &lt;strong&gt;SeriesServices.cs &lt;/strong&gt;and &lt;strong&gt;SeriesService.metadata.cs&lt;/strong&gt;.&amp;#160; It is alright to modify these files as they are only generated once.&lt;/p&gt;  &lt;p&gt;By using the &lt;strong&gt;SilverLight Business Application&lt;/strong&gt; template, there is something else going on behind the scenes.&amp;#160; VS is looking for these metadata files and is using them to project your classes out to your SilverLight application so they can be used transparently there, with the same namespace I might add.&amp;#160; I find it helpful to include this generated file in the solution, otherwise your code looks like its broken until you compile:&lt;a href="http://lh5.ggpht.com/_McWINbq-D3o/SrBSTM60jYI/AAAAAAAAAEo/i6NVWcfEshs/s1600-h/image201.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_McWINbq-D3o/SrBSUTWTVQI/AAAAAAAAAEs/0zndvMUm6Y8/image20_thumb1.png?imgmax=800" width="230" height="562" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Notice the file &lt;strong&gt;AnimeManager6.Web.g.cs&lt;/strong&gt;, this is a generated file which contains a representation of the classes in Silverlight.&amp;#160; The one key thing to remember is that your service class (&lt;strong&gt;SeriesService&lt;/strong&gt; in this case) will get generated as a context class instead (&lt;strong&gt;SeriesContext&lt;/strong&gt; in this case).&amp;#160; So the code to bind a datagrid would look something like this:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnNavigatedTo(NavigationEventArgs e)
{
     SeriesContext sc = &lt;span class="kwrd"&gt;new&lt;/span&gt; SeriesContext();
     sc.Load(sc.GetSeriesQuery());
     myDataGrid.ItemsSource = sc.Series;
}&lt;/pre&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;p&gt;&lt;/p&gt;

&lt;p&gt;Note that while this doesn’t appear as such, this is an asynchronous call.&amp;#160; You will find the definition of &lt;strong&gt;GetSeriesQuery&lt;/strong&gt; as &lt;strong&gt;GetSeries&lt;/strong&gt; in your &lt;strong&gt;SeriesService &lt;/strong&gt;method as it is auto generated.&amp;#160; The result is returned, in this case, the &lt;strong&gt;Series &lt;/strong&gt;property of the context, if it where a list of a different type it would likely go there.&amp;#160; This means that attempting to step through this in real time is useless, more often then note you will get an empty set from &lt;strong&gt;Series&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As this object is right now, attempting to bind to either our Studio reference or Genres collection would not yield anything. You have to include these data points via the &lt;em&gt;Include &lt;/em&gt;when you query the context, and in the case of Studio, mark it with the &lt;strong&gt;Include&lt;/strong&gt; attribute to get VS to project it to the SilverLight class representations.&lt;/p&gt;

&lt;p&gt;So lets first take care of the &lt;strong&gt;Studio&lt;/strong&gt; reference, open up your metadata file and add the &lt;strong&gt;[Include] &lt;/strong&gt;attribute to the reference:&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_McWINbq-D3o/SrBSV0ocbBI/AAAAAAAAAEw/fg_F3PC5wqk/image%5B8%5D.png?imgmax=800" width="455" height="536" /&gt;&lt;/p&gt;

&lt;p&gt;You will note that we are also applying it to the &lt;strong&gt;SeriesGenres&lt;/strong&gt; property, more on this in one second.&amp;#160; With this change in place, update your XAML to look for the &lt;em&gt;Studio&lt;strong&gt;&amp;#160;&lt;/strong&gt;&lt;/em&gt;navigation property and access its &lt;strong&gt;Name&lt;/strong&gt; property: ie &lt;strong&gt;{Binding &lt;/strong&gt;&lt;em&gt;Studio.Name&lt;strong&gt;}&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now this is all good and fine and you may be thinking about extending the projected version of &lt;strong&gt;Series &lt;/strong&gt;in the SilverLight project to include custom properties; don’t, this doesn’t work. I am not entirely sure why, but I will show you how to extend the class and in my mind its a better way anyway.&lt;/p&gt;

&lt;p&gt;The best way to add these custom properties is by extending the generated models themselves.&amp;#160; In this case, this is the code I used to create a property for Series which lists out its Genres in a comma delimited list:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Series
{
    [DataMember]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GenreDisplay
    {
        get
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (SeriesGenres.Count &amp;gt; 0)
            {
                var sb = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();
                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var genre &lt;span class="kwrd"&gt;in&lt;/span&gt; SeriesGenres)
                {
                    sb.Append(genre.Genre.Name);
                    sb.Append(&lt;span class="str"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;);
                }

                &lt;span class="kwrd"&gt;return&lt;/span&gt; sb.ToString().Substring(0, sb.ToString().Length - 2);
            }

            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;No Genres&amp;quot;&lt;/span&gt;;
        }
    }
}&lt;/pre&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;p&gt;The key thing here is the &lt;strong&gt;[DataMember] &lt;/strong&gt;attribute, which causes it to be included in the serialization down to the client.&amp;#160; By doing this, it is automatically available to use in the XAML.&amp;#160; Bare in mind that as this being done purely on the server before the object is sent down, it is ONLY reliant on either the &lt;strong&gt;EntityContext &lt;/strong&gt;being open or &lt;em&gt;Include &lt;/em&gt;being used when making the query.&amp;#160; It doesn’t not require the objects themselves to use the &lt;strong&gt;[Include]&lt;/strong&gt; attribute.&lt;/p&gt;

&lt;p&gt;This gives you flexibility in the design of the class.&amp;#160; It is my opinion, that the generated code is sealed for a reason and modifying the metadata file is likely not a good idea, as this may be something you want to regenerate over time.&amp;#160; However, the other effect of using the &lt;strong&gt;[DataMember]&lt;/strong&gt; attribute will cause VS to project the property out to the SilverLight project automatically.&lt;/p&gt;

&lt;p&gt;I hope this helps out, getting this information took me some time and drove me nuts in getting it to work.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-6737088047280926263?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1HDSN4mpXaXJf37R4hHAKvOPSiw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1HDSN4mpXaXJf37R4hHAKvOPSiw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1HDSN4mpXaXJf37R4hHAKvOPSiw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1HDSN4mpXaXJf37R4hHAKvOPSiw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/eFebGCjjkAs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/6737088047280926263/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=6737088047280926263" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/6737088047280926263?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/6737088047280926263?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/eFebGCjjkAs/experiments-with-ria-services.html" title="Experiments with RIA Services" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/09/experiments-with-ria-services.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkQMQXs8fCp7ImA9WxNRFU8.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-8052733897506566183</id><published>2009-09-09T13:33:00.000-07:00</published><updated>2009-09-09T13:33:00.574-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-09T13:33:00.574-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Implemenation" /><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><category scheme="http://www.blogger.com/atom/ns#" term="Coolite" /><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><category scheme="http://www.blogger.com/atom/ns#" term="ExtJS" /><title>Performing ASP .NET Submits with Coolite Form Panel Events</title><content type="html">&lt;p&gt;As with anything in programming there are a number of ways to do any operation, sending data to server side code in Coolite is no exception.&amp;#160; One of the ways that I have found very useful is via the OnEvent configuration for an AjaxEvent.&lt;/p&gt;  &lt;p&gt;To begin with one needs to understand that a FormPanel is not a representation of the &amp;lt;form&amp;gt; tag from HTML, but rather similar to the UpdatePanel control from ASP .NET Ajax.&amp;#160; AjaxEvents are then like triggers.&amp;#160; However, since this trigger could reside anywhere on the page we need a way to “link” the panel viewstate to the trigger so the ViewState is transmitted and we get the desired information that we need.&amp;#160; This is done via the &lt;strong&gt;FormID&lt;/strong&gt; attribute on both the &lt;strong&gt;AjaxEvent&lt;/strong&gt; and the &lt;strong&gt;FormPanel&lt;/strong&gt;.&amp;#160; In addition, fields that are to be transmitted seem to require a Layout, meaning they cannot simply be placed adhoc on the page.&amp;#160; Thus the initial HTML fragment looks something like this:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:FormPanel&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;fpMain&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;FormID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;mainForm&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;ButtonAlign&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Right&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;My Form&amp;quot;&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;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;ext:FormPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&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&gt;

&lt;p&gt;I am only defining a few of the essential properties here.&amp;#160; As I said earlier, &lt;strong&gt;FormID&lt;/strong&gt; helps Coolite identify which ViewState set to submit as part of the AjaxEvent.&amp;#160; All Panels in Coolite have a section dedicated for buttons, we can use the &lt;strong&gt;ButtonAlign&lt;/strong&gt; property align those buttons as we wish.&lt;/p&gt;

&lt;p&gt;For the next segment I will define a could fields using the &lt;strong&gt;FormLayout&lt;/strong&gt; control. Understand that this Layout in particular has a lot of extra functionality and uses, I am not going to show case all of them here.&amp;#160; I will talk about it later on, for now I would advise visiting &lt;a href="http://examples.coolite.com"&gt;http://examples.coolite.com&lt;/a&gt; and looking under the ‘&lt;strong&gt;Layouts’&lt;/strong&gt; section.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:FormPanel&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;fpMain&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;strong&gt;&lt;span class="attr"&gt;FormID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;mainForm&amp;quot;&lt;/span&gt;&lt;/strong&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="attr"&gt;ButtonAlign&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Right&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;My Form&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&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;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:FormLayout&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;LabelSeparator&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;:&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="attr"&gt;LabelAlign&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Left&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Anchor&lt;/span&gt; &lt;span class="attr"&gt;Horizontal&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;95%&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                 &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:TextField&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;txtName&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;                     &lt;span class="attr"&gt;FieldLabel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:Anchor&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Anchor&lt;/span&gt; &lt;span class="attr"&gt;Horizontal&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;95%&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                 &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:NumberField&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nbrAge&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;                    &lt;span class="attr"&gt;FieldLabel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Age&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;3&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:Anchor&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:FormLayout&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&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;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Buttons&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnSubmit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Submit&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Accept&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AjaxEvents&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Click&lt;/span&gt; &lt;strong&gt;&lt;span class="attr"&gt;OnEvent&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnSubmit_Click&amp;quot;&lt;/span&gt;&lt;/strong&gt; &lt;strong&gt;&lt;span class="attr"&gt;FormID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;mainForm&amp;quot;&lt;/span&gt;&lt;/strong&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EventMask&lt;/span&gt; &lt;span class="attr"&gt;ShowMask&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Msg&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Submitting Data&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;                        &lt;span class="attr"&gt;CustomTarget&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;fpMain&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Target&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CustomTarget&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;AjaxEvents&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Buttons&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:FormPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&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;p&gt;&lt;/p&gt;

&lt;p&gt;So I have defined here two form fields within &lt;strong&gt;FormLayout&lt;/strong&gt; one holds a normal textfield and the other a numbers only field.&amp;#160; To finish this implementation we need to define the &lt;strong&gt;btnSubmit_Click&lt;/strong&gt; event handler in the code behind file.&amp;#160; The implementation I will use is:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnSubmit_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, AjaxEventArgs ev)
{
    Ext.Msg.Alert(&lt;span class="str"&gt;&amp;quot;Alert&amp;quot;&lt;/span&gt;,
        &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;Welcome {0} (Age {1}). Today is {2:d}&amp;quot;&lt;/span&gt;,
            txtName.Text, nbrAge.Text, DateTime.Now))
    .Show();
}&lt;/pre&gt;

&lt;p&gt;Admitting, this is a very simple concept of what a server side event could do; it simply shows a Coolite style modal that is designed to substitute the standard JavaScript alert window.&amp;#160; Here we are basically telling the user the information they entered as well as attaching a server side piece of data (the current date).&amp;#160; You can image business logic being here for adding this data to a persistent store, such as a database. I will save another blog entry to talk about validating this data since Coolite can take care of a great deal of that for you.&lt;/p&gt;

&lt;p&gt;One other interesting thing to note, and is something that I have observed. When you start getting into these sorts of scenarios where you are using these events, you will want to be conscious of the fact that even though Coolite states the &amp;lt;form runat=”server”&amp;gt; tag is not needed in the little docs they have, &lt;strong&gt;this is false&lt;/strong&gt;.&amp;#160; You will find this very true when you start trying to submit changes to a grid or pick up what rows of a grid where selected. I will have an example of this next.&lt;/p&gt;

&lt;p&gt;The key thing here is to understand the connection between &lt;strong&gt;FormPanel&lt;/strong&gt; and how to send data from the client to the server is a way that is more familiar to ASP .NET web programmers.&amp;#160; Remember to mindful of the view state you are including and you can always validate things are working by checking the state of form fields on the server, I still do this at the onset, just to be sure I know what I am submitting.&lt;/p&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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-8052733897506566183?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6oN6bU3L1Q8hzBRrUgf1B6lCXD0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6oN6bU3L1Q8hzBRrUgf1B6lCXD0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6oN6bU3L1Q8hzBRrUgf1B6lCXD0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6oN6bU3L1Q8hzBRrUgf1B6lCXD0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/vMJyQlFkTGE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/8052733897506566183/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=8052733897506566183" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8052733897506566183?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8052733897506566183?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/vMJyQlFkTGE/performing-asp-net-submits-with-coolite.html" title="Performing ASP .NET Submits with Coolite Form Panel Events" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/09/performing-asp-net-submits-with-coolite.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEMQXwzcSp7ImA9WxNRE0k.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-3870232561013509392</id><published>2009-09-07T09:58:00.000-07:00</published><updated>2009-09-07T09:58:00.289-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-07T09:58:00.289-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><title>Using .NET Extension Methods for Type Conversion Libraries</title><content type="html">&lt;p&gt;One of my favorite features in Microsoft .NET is extension methods, primarily because of the clean syntax they provide for formatting and perform special operations against types.&amp;#160; I never really never did like static helper methods like this:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;DecimalHelper.FormatAsMoney(decimalValue);&lt;/pre&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;p&gt;I just felt that this was not clean and felt more procedural then it should in an object oriented language like .NET.&amp;#160; Nonetheless, it satisfied the need of being able to centralize logic for dealing with certain common conditions, least of all Type conversion (ala the &lt;strong&gt;Convert&lt;/strong&gt; class).&amp;#160; With the advent of the LINQ syntax in .NET 3.5 Microsoft provided support for using extension methods.&amp;#160; These superficially attached methods are my favorite feature in .NET as they are able to achieve the same result as the helper methods above, except with a much cleaner syntax in my opinion:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;decimalVaue.AsMoney();&lt;/pre&gt;

&lt;p&gt;So I started thinking, this would be very useful for creating “smart parsers” for converting types, in particular strings to various data types, a common and often tedious exercise in web applications.&amp;#160; Smart parsers encapsulate the calls to &lt;strong&gt;TryParse&lt;/strong&gt; and allow the method call to return a standard value on fail or, with an overload, return a default value.&amp;#160; This is an example of my &lt;strong&gt;AsInt&lt;/strong&gt; smart parser function:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; AsInt(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; s)
{
    &lt;span class="kwrd"&gt;int&lt;/span&gt; d;
    &lt;span class="kwrd"&gt;return&lt;/span&gt; !&lt;span class="kwrd"&gt;int&lt;/span&gt;.TryParse(s, &lt;span class="kwrd"&gt;out&lt;/span&gt; d)
        ? &lt;span class="kwrd"&gt;int&lt;/span&gt;.MinValue : d;
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; AsInt(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; s, &lt;span class="kwrd"&gt;int&lt;/span&gt; defValue)
{
    &lt;span class="kwrd"&gt;int&lt;/span&gt; d = s.AsInt();
    &lt;span class="kwrd"&gt;return&lt;/span&gt; d == &lt;span class="kwrd"&gt;int&lt;/span&gt;.MinValue
        ? defValue : d;
}&lt;/pre&gt;

&lt;p&gt;I always did hate calls to &lt;strong&gt;Convert&lt;/strong&gt; and &lt;strong&gt;TryParse&lt;/strong&gt; cause I felt the code was dirty and parsing in general sometimes needs to aware of Globalization settings.&amp;#160; As a result of the success I have had using this on many enterprise projects, I have made it a standard that I implement.&amp;#160; I decided recently, at the advisement of a co-worker to publish something. Its not much, but its a few of the standard methods that I work with.&amp;#160; A lot of these sort of methods are born out of a need to create consistency in the application, mostly related to formatting.&lt;/p&gt;

&lt;p&gt;Below is the link to download what I currently have developed (along with some unit tests).&amp;#160; I hope to have this grow into a full fledged type conversion and formatting library.&lt;/p&gt;
&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-18f9d8896416d2fb.skydrive.live.com/embedrowdetail.aspx/BlogFiles/Core.Extensions.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&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;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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-3870232561013509392?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4rFZq2wt2y2gzImXzADuGuKEqDQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4rFZq2wt2y2gzImXzADuGuKEqDQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4rFZq2wt2y2gzImXzADuGuKEqDQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4rFZq2wt2y2gzImXzADuGuKEqDQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/5Mpd-Syk9tE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/3870232561013509392/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=3870232561013509392" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/3870232561013509392?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/3870232561013509392?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/5Mpd-Syk9tE/using-net-extension-methods-for-type.html" title="Using .NET Extension Methods for Type Conversion Libraries" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/09/using-net-extension-methods-for-type.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EAQnY6eSp7ImA9WxNREU0.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-7736753568672711155</id><published>2009-09-04T17:14:00.001-07:00</published><updated>2009-09-04T17:14:03.811-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-04T17:14:03.811-07:00</app:edited><title>Grouping with Coolite GridPanel</title><content type="html">&lt;p&gt;One of the nicest things about Coolite is that you can easily get a very modern looking website in short order, provided you take the time to understand the examples and ExtJS documentation, which maps pretty closely to the controls.&amp;#160; But there are still little niches you need to know to get the controls to work how you want.&amp;#160; One of the most finicky controls, I have found is the GridPanel.&lt;/p&gt;  &lt;p&gt;So much interactivity can be achieved these days via JSON and grids it really is breathtaking when you pull it off.&amp;#160; Coolite is no exception, in fact, when configured properly, it has one of the must full featured grids I have seen on the web, once you get there that is. I will talk about the grid a lot in posts to come, primarily about databinding, and updating.&amp;#160; But today we will focus on grouping.&lt;/p&gt;  &lt;p&gt;Grouping is an effect where by a top level is rendered based on data groups, these can be expanded to show the children of that group along with aggregation data.&amp;#160; Today I am going to explain how to take a simple array of data and generate a grid panel which supports grouping.&amp;#160; To begin, here is some sample data we will feed our grid:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;var aList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Order&amp;gt;()&lt;/pre&gt;

  &lt;pre&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 100, ProductId = 3,&lt;/pre&gt;

  &lt;pre&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 3&amp;quot;&lt;/span&gt;, UnitPrice = 5.00m,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        Quantity = 21 },&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 100, ProductId = 6,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 6&amp;quot;&lt;/span&gt;, UnitPrice = 1.00m,&lt;/pre&gt;

  &lt;pre&gt;        Quantity = 22 },&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 100, ProductId = 7,&lt;/pre&gt;

  &lt;pre&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 7&amp;quot;&lt;/span&gt;, UnitPrice = 2.00m,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        Quantity = 23 },&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 200, ProductId = 3,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 3&amp;quot;&lt;/span&gt;, UnitPrice = 3.00m,&lt;/pre&gt;

  &lt;pre&gt;        Quantity = 24 },&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 300, ProductId = 4,&lt;/pre&gt;

  &lt;pre&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 4&amp;quot;&lt;/span&gt;, UnitPrice = 4.00m,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        Quantity = 25 },&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 400, ProductId = 5,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 5&amp;quot;&lt;/span&gt;, UnitPrice = 5.00m,&lt;/pre&gt;

  &lt;pre&gt;        Quantity = 26 },&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 500, ProductId = 8,&lt;/pre&gt;

  &lt;pre&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 8&amp;quot;&lt;/span&gt;, UnitPrice = 6.00m,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        Quantity = 27 },&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 500, ProductId = 9,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 9&amp;quot;&lt;/span&gt;, UnitPrice = 7.00m,&lt;/pre&gt;

  &lt;pre&gt;        Quantity = 28 },&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 500, ProductId = 1,&lt;/pre&gt;

  &lt;pre&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 1&amp;quot;&lt;/span&gt;, UnitPrice = 8.00m,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        Quantity = 29 },&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 200, ProductId = 2,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 2&amp;quot;&lt;/span&gt;, UnitPrice = 9.00m,&lt;/pre&gt;

  &lt;pre&gt;        Quantity = 20 },&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 700, ProductId = 3,&lt;/pre&gt;

  &lt;pre&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 3&amp;quot;&lt;/span&gt;, UnitPrice = 1.00m,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        Quantity = 21 },&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 700, ProductId = 4,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 4&amp;quot;&lt;/span&gt;, UnitPrice = 2.00m,&lt;/pre&gt;

  &lt;pre&gt;        Quantity = 22 },&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; Order() { OrderId = 800, ProductId = 4,&lt;/pre&gt;

  &lt;pre&gt;        ProductName=&lt;span class="str"&gt;&amp;quot;Product 4&amp;quot;&lt;/span&gt;, UnitPrice = 3.00m,&lt;/pre&gt;

  &lt;pre class="alt"&gt;        Quantity = 23 }&lt;/pre&gt;

  &lt;pre&gt;};&lt;/pre&gt;
&lt;/div&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;p&gt;&lt;/p&gt;

&lt;p&gt;Ok, maybe that was a bit excessive, but moving on.&amp;#160; Coolite emphasis a UI pattern I like to call “late loading”. The basics of this pattern is that the main frame of the page should come in first and then the data. This gives the user the impression of a page load and lightens the load. This technique is commonly employed with data heavy applications which utilize a single page architecture and simply move data (usually in JSON) to and from the server using asynchronous calls.&lt;/p&gt;

&lt;p&gt;My favorite way of getting data with Coolite are ASP .NET Generic Handlers (.ashx), mainly because they are extremely lightweight and have some very nice uses with GridPanels. This is the code for the ASHX, notice the use of the &lt;a href="http://www.codeplex.com/Json" target="_blank"&gt;NewtonSoft JSON Library&lt;/a&gt; (this is included with the Coolite download) to serialize the List into JSON and pass it back, also notice the content type definition, to &lt;strong&gt;text/json&lt;/strong&gt;.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[WebService(Namespace = &lt;span class="str"&gt;&amp;quot;http://tempuri.org/&amp;quot;&lt;/span&gt;)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DataHandler : IHttpHandler
{
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ProcessRequest(HttpContext context)
        {
            List&amp;lt;Order&amp;gt; list = Order.GetData();

            context.Response.ContentType = &lt;span class="str"&gt;&amp;quot;text/json&amp;quot;&lt;/span&gt;;
            StoreResponseData data = &lt;span class="kwrd"&gt;new&lt;/span&gt; StoreResponseData();
            data.Data = JSON.Serialize(list);
            data.Return();
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsReusable
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
            }
    }
}&lt;/pre&gt;

&lt;p&gt;What this will do is return a JSON object to be read by a Coolite ExtJS data store and then bound to a control.&amp;#160; In this case, the data that is being returned can easily be grouped by its OrderId property. We can have Coolite take care of most the heavy lifting for us.&amp;#160; So we will first define our data store:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Store&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;store&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AutoLoad&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="attr"&gt;AutoDataBind&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;GroupField&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;OrderId&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Proxy&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:HttpProxy&lt;/span&gt; &lt;span class="attr"&gt;DisableCaching&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Json&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;            &lt;span class="attr"&gt;Method&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;GET&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Url&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;/DataHandler.ashx&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Proxy&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Reader&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:JsonReader&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Fields&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:RecordField&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;OrderId&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:RecordField&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ProductId&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:RecordField&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ProductName&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:RecordField&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UnitPrice&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:RecordField&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Quantity&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:RecordField&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Total&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Fields&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:JsonReader&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Reader&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:Store&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&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;p&gt;Ok there is a lot here so we will go line by line.&amp;#160; First we are defining the Store and saying that we want it to AutoLoad which means a request will be made as the page becomes ready.&amp;#160; The key here is the &lt;strong&gt;GroupField&lt;/strong&gt; definition which is what will format the outgoing result in a way that the GridPanel will use a grouping format to output it.&lt;/p&gt;

&lt;p&gt;The connections to the data sources are initiated through Proxies.&amp;#160; The interesting thing here is that you can also define a WriteProxy to handle changes to Store via the Grids inline editing feature.&amp;#160; In this tutorial we are only going to be covering using a ReadProxy:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;DisableCaching&lt;/strong&gt;: This prohibits the browser from caching a request. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Json&lt;/strong&gt;: This just ensures that what we get back from the request is JSON, I define this just to be explicit with what is coming back &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Method&lt;/strong&gt;: Once again this overloads the default value, and just explicitly states that we wish this request to be carried out over GET &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Url&lt;/strong&gt;: The URL of where to make the request to, in this case we are specifying the URL to our custom ASHX &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next part is the &lt;strong&gt;Reader&lt;/strong&gt; definition; this is defining what the JSON object is going to look like on the client side as it is worked with on the client side.&amp;#160; Make sure the values of the &lt;strong&gt;Name&lt;/strong&gt; attributes match their respective property values of on the JSON object coming over.&amp;#160; I mistakenly thought this was the order of serialization, but it is not; they match one to one.&amp;#160; You can optionally define the &lt;strong&gt;Type&lt;/strong&gt; attribute, but for the most part Coolite will infer the types.&lt;/p&gt;

&lt;p&gt;With this defined, we are now ready to move onto defining our GridPanel which will actually provide the UI for the user to see.&amp;#160; &lt;em&gt;The definition is rather long, so I will be breaking this apart based on the internal nodes for definition&lt;/em&gt;, to start here is the outer structure which has the base property definitions:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:GridPanel&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;gpPanel&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AutoHeight&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;StripeRows&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;StoreID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;store&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AutoDataBind&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&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;ext:GridPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;&lt;span class="kwrd"&gt;The important attributes here &lt;strong&gt;StoreID &lt;/strong&gt;(which defines which store this control is associated with), also &lt;strong&gt;AutoDataBind&lt;/strong&gt; which will automatically rebind the grid whenever a change is detected in the associated store.&amp;#160; The other attributes are defined for aesthetic purposes.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;The next thing to do is to define how the grid will look without Grouping and what columns will be included, to do this we define a ColumnModel node within the GridPanel:&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnModel&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&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;Columns&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;ext:Column&lt;/span&gt; &lt;span class="attr"&gt;DataIndex&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;OrderId&amp;quot;&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;ext:Column&lt;/span&gt; &lt;span class="attr"&gt;DataIndex&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ProductName&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Header&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Product&amp;quot;&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;ext:Column&lt;/span&gt; &lt;span class="attr"&gt;DataIndex&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UnitPrice&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Header&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Price&amp;quot;&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;Renderer&lt;/span&gt; &lt;span class="attr"&gt;Format&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UsMoney&amp;quot;&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;ext:Column&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;ext:Column&lt;/span&gt; &lt;span class="attr"&gt;DataIndex&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Quantity&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Header&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Qty&amp;quot;&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;ext:Column&lt;/span&gt; &lt;span class="attr"&gt;DataIndex&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Total&amp;quot;&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;Renderer&lt;/span&gt; &lt;span class="attr"&gt;Format&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UsMoney&amp;quot;&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;ext:Column&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;Columns&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;ColumnModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;/p&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;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;p&gt;You notice the DataIndex matches the value of the &lt;strong&gt;Name&lt;/strong&gt; attribute from the JsonReader RecordFields.&amp;#160; Understand that the column model defines ONLY what fields from the JSON object you want to display.&amp;#160; The row will STILL contain a reference to the whole JSON object, but this way you can choose to hide fields like PKs (We are doing this with ProductId in this case), but they are still usable when a GridCommand is invoked.&lt;/p&gt;

&lt;p&gt;Notice also that we are using the built in Render formatting that is provided by Coolite.&amp;#160; There are quite a few of them that come out of the box, in addition you can define your own.&lt;/p&gt;

&lt;p&gt;So if you run this code right now, you will get a simple grid, but you will still not see any groupings, this is because we need to define a GroupingView node for this GridPanel to see the grouping in action.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;View&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;ext:GroupingView&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;gvGrouping&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;
        &lt;span class="attr"&gt;ForceFit&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;HideGroupedColumn&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&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;ext:GroupingView&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;View&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Views are an extremely vital piece to the GridPanel as they can help you define further configuration in terms of function and formatting.&amp;#160; Here we are using the GroupingView which defines how the Grid will look when it is grouping.&amp;#160; We define two attributes for aesthetical purposes: &lt;strong&gt;ForceFit &lt;/strong&gt;and &lt;strong&gt;HideGroupedColumn&lt;/strong&gt;.&amp;#160; ForceFit merely forces the Grid to fit its entire available width, it tends to make the grid look a lot nicer.&amp;#160; HideGroupedColumn hides the column you are grouping on.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Running the code now you will see the GridPanel and your data grouped by the OrderId.&amp;#160; The blocks are expandable and collapsible, and their initial state can be defined on the GroupingView.&amp;#160; The GridPanel offers an immense amount of functionality and can really help you display your data.&amp;#160; It also best demonstrates ExtJs reliance on the “late-load” content loading technique.&amp;#160; Your controls will be rendered and the data will be brought in via Store’s that in most cases will be linked to a web service of some kind.&amp;#160; This data is then placed into either an Array, JSON, or XML, depending on what you define. In our example, we used JSON.&amp;#160; We associated this Store with a Grid via the StoreID attribute of the GridPanel.&amp;#160; In addition, we define the Grouping column for the Store, this is what enables our grouping.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Finally, we use a ColumnModel and View to define how the Grid will look under certain situations.&amp;#160; Remember that you do not have to define a column for all members of your JSON object, only the ones you want to display, sending a row command will still give you access to all the properties defined on the object via the JSON reader.&lt;/span&gt;&lt;/p&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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-7736753568672711155?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/HLUuPY8asPkAKVSfdfFYeiJ9MZQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HLUuPY8asPkAKVSfdfFYeiJ9MZQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/HLUuPY8asPkAKVSfdfFYeiJ9MZQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HLUuPY8asPkAKVSfdfFYeiJ9MZQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/czqwP1Ttyt0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/7736753568672711155/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=7736753568672711155" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/7736753568672711155?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/7736753568672711155?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/czqwP1Ttyt0/grouping-with-coolite-gridpanel.html" title="Grouping with Coolite GridPanel" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/09/grouping-with-coolite-gridpanel.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYFR387eyp7ImA9WxNSE0U.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-918097202578573262</id><published>2009-08-26T20:00:00.001-07:00</published><updated>2009-08-27T06:35:16.103-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-27T06:35:16.103-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Implemenation" /><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Coolite" /><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><title>Creating Modal Windows with Coolite</title><content type="html">&lt;p&gt;One of the most popular effects in web development, is the modal dialog.&amp;#160; Using standard CSS we are able to create the appearance of a modal dialog on a webpage that can be used to provide a quick login form, more information, or any of a thousand other things.&amp;#160; Naturally, most UI frameworks have this effect built-in so developers can quickly create this effect without having to worry about cross browser problems; Coolite is no exception.&lt;/p&gt;  &lt;p&gt;Generally, the way this is achieved is a &amp;lt;div&amp;gt; is placed somewhere on the page (usually at the bottom) and is targeted with JavaScript which does some fanciness to give it various look-and-feel properties.&amp;#160; Coolite is slightly different, but in a way that makes more sense.&amp;#160; It leverages the idea of the “viewport” as the main page, that is what the user see’s without the modal.&amp;#160; In Coolite we would define this as such:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:ViewPort&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;vp1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AutoHeight&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&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;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;ext:ViewPort&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;The basic idea here is that the viewport serves as a wrapper for your main content.&amp;#160; So we could define our main UI here, for this example we will simple put a button which opens the modal.&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:ViewPort&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;vp1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AutoHeight&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&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;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnOpen&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Open&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Application&amp;quot;&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;Listeners&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;Listeners&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;ext:Button&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;ext:ViewPort&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Next we define the code for our Modal window, for this example, we are going to constrain the width and put some lipsum text&lt;/span&gt;&lt;/p&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;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;ext:Window&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Window1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AutoHeight&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;400&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Constrain&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Modal&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ShowOnLoad&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ButtonAlign&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Right&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Modal Window&amp;quot;&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;
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
        has been the industry's standard dummy text ever since the 1500s, when an unknown printer
        took a galley of type and scrambled it to make a type specimen book. It has survived not
        only five centuries, but also the leap into electronic typesetting, remaining essentially
    &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;Buttons&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;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnClose&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Close&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Cancel&amp;quot;&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;Buttons&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;ext:Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;So this is fairly simple and straightforward.&amp;#160; We have defined our main layout in a ViewPort and then we have defined external layout elements (the modal) in Windows that are defined outside the ViewPort.&amp;#160; I defined only the essential properties of the modal, but there are quite a few properties, such as X and Y to define the starting location of the modal.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;However, we are missing one critical element; with this current code there is no way to show the modal to the user.&amp;#160; There are two ways to do this, and your selection of the means to do this will depend on your scenario.&amp;#160; You can open this with both JavaScript and the .NET code behind.&amp;#160; In JavaScript, we simply add a listener node and listen for the “Click” event.&amp;#160; Thus our buttons definition looks like this:&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnOpen&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Open&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Application&amp;quot;&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;Listeners&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;Click&lt;/span&gt; &lt;span class="attr"&gt;Handler&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Window1.show();&amp;quot;&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;Listeners&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;ext:Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;This is the approach I like to take for simple calls, just define the Handler property with the JavaScript you want.&amp;#160; Its a “do it once and throw it away'”.&amp;#160; However, if you’re going to duplicate logic and call it throughout the page, I would then define the Fn property and centralize all that logic in a single function.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;In addition, the Window component has many events that you can catch, with JavaScript or Server-side code, though client side will be much easier to understand.&amp;#160; I will list out some of the more useful ones that I have used:&lt;/span&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;span class="kwrd"&gt;&lt;strong&gt;BeforeShow&lt;/strong&gt; – fires just before the modal is shown to the user.&amp;#160; Useful as a means of resetting modal content from an pre-existing operation.&lt;/span&gt; &lt;/li&gt;

  &lt;li&gt;&lt;span class="kwrd"&gt;&lt;strong&gt;BeforeHide – &lt;/strong&gt;fires just before the modal disappears from the users view&lt;/span&gt; &lt;/li&gt;

  &lt;li&gt;&lt;span class="kwrd"&gt;&lt;strong&gt;Hide – &lt;/strong&gt;fires after the modal is closed via a call to hide() on the Window element&lt;/span&gt; &lt;/li&gt;

  &lt;li&gt;&lt;span class="kwrd"&gt;&lt;strong&gt;Show&lt;/strong&gt; – fires after the modal is shown to the user&lt;/span&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;So as I mentioned the same effect can be accomplished using AjaxEvents.&amp;#160; To do this you would simply update the Button definition removing the &amp;lt;Listeners&amp;gt; node with the &amp;lt;AjaxEvents&amp;gt; note, like such:&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnOpen&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Open&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Application&amp;quot;&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;AjaxEvents&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;Click&lt;/span&gt; &lt;span class="attr"&gt;OnEvent&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnOpen_Click&amp;quot;&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;EventMask&lt;/span&gt; &lt;span class="attr"&gt;ShowMask&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;Msg&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;This is a Loading Mask&amp;quot;&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;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;AjaxEvents&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;ext:Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;This defines that for the button the Click event raises an AjaxEvent which is handled by the &lt;em&gt;btnOpen_Click&lt;/em&gt; method in the page code behind.&amp;#160; From this position you have access to &lt;em&gt;related&lt;/em&gt; page elements.&amp;#160; What does it mean to be related?&amp;#160; I honestly dont know, this is one of the aspects of Coolite that is largely undocumented.&amp;#160; From what I can gather, it seems to be the parent container, though you can define a specific form to link to the AjaxEvent, via the FormID attribute.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Notice that we are also defining a mask to be visible when this event is occurring.&amp;#160; Remember that we are going back to the server, so it makes sense to give the user some feedback; thus in the event the operation takes time the user is notified and appropriate interactions can be prevented.&amp;#160; To give you an idea what the code behind method looks like in this case, here is what &lt;em&gt;btnOpen_Click&lt;/em&gt; looks like:&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnOpen_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs ev)
{
    Window1.Show();
}&lt;/pre&gt;

&lt;p&gt;Very simple and straightforward.&amp;#160; You could imagine having checks in here to prevent the modal from showing if certain conditions were not met, or populating modal elements with server data.&lt;/p&gt;

&lt;p&gt;To conclude, the big thing to remember about Coolite modals, is that they must be placed outside a ViewPort component with the &lt;strong&gt;Modal &lt;/strong&gt;property set to &lt;em&gt;true&lt;/em&gt;.&amp;#160; There a wide variety of properties that you can configure for the window to improve the look and feel of the modal as well as positioning.&amp;#160; Modals provide a great way to display related information or provide a drill down into data, they can be used to simplify interfaces and provide more elegant ways to access commonly used functionality, while continuing to move the web application closer to the goal of behaving like a desktop application.&lt;/p&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;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;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;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;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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-918097202578573262?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WvLQ7BFp2twjqW9shqlABfMaYvo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WvLQ7BFp2twjqW9shqlABfMaYvo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WvLQ7BFp2twjqW9shqlABfMaYvo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WvLQ7BFp2twjqW9shqlABfMaYvo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/lxaXkvzUNNc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/918097202578573262/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=918097202578573262" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/918097202578573262?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/918097202578573262?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/lxaXkvzUNNc/creating-modal-windows-with-coolite.html" title="Creating Modal Windows with Coolite" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/08/creating-modal-windows-with-coolite.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UEQ3o8eip7ImA9WxNSEUg.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-1351602790115193555</id><published>2009-08-24T15:00:00.000-07:00</published><updated>2009-08-24T15:00:02.472-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-24T15:00:02.472-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Implemenation" /><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Coolite" /><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><category scheme="http://www.blogger.com/atom/ns#" term="ExtJS" /><title>Understanding AjaxEvents in Coolite ASP .NET</title><content type="html">&lt;p&gt;In the first tutorial in this series we created a very basic Hello form that relied on JavaScript for its core.&amp;#160; We also saw how easy it was to build a very clean and modern looking form using Coolite.&amp;#160; But what are there things called AjaxEvents.&lt;/p&gt;  &lt;p&gt;Going to the Coolite website we find that, as with most of Coolite, there is a total lack of documentation as to what AjaxEvents are, although there are samples showing how to use them.&amp;#160; Based on these examples I would say they are simple postback requests that can be used to post data to the server.&lt;/p&gt;  &lt;p&gt;They are able to “target” a specific form (they default to the form they are in) and send the current state of the items in that form to the ASP .NET code behind where they can be operated on as desired.&amp;#160; These requests are then able to fire the events of other controls that have events defined (ex Grid, Store). In addition, you are able to configure an event mask for while the request is in process. This helps the user know that “something is happening”.&lt;/p&gt;  &lt;p&gt;So to begin here is a screenshot of code from the first tutorial, but I have cut the JavaScript out and removed the Listeners node from the Button   &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_McWINbq-D3o/SpGtjmTSBUI/AAAAAAAAAD8/Xz6IPB5B8fc/image%5B6%5D.png?imgmax=800" width="472" height="306" /&gt;&lt;/p&gt;  &lt;p&gt; The first step is to update the Button markup as such:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Buttons&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;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnSubmit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;
   &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Submit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Accept&amp;quot;&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;AjaxEvents&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;Click&lt;/span&gt; &lt;span class="attr"&gt;OnEvent&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnSubmit_Click&amp;quot;&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;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;AjaxEvents&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;ext:Button&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;Buttons&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;Very similar to the &amp;lt;Listeners&amp;gt; node (and in fact these can be combined with a listener, return false, will stop the request), we are saying that “when the &lt;strong&gt;Click&lt;/strong&gt; event occurs, create an &lt;strong&gt;AjaxEvent&lt;/strong&gt; which is handled by the handler &lt;strong&gt;btnSubmit_Click&lt;/strong&gt; in the code behind”.&amp;#160; This what our handler could look like:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnSubmit_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
     AjaxEventArgs ev)
{
     Ext.Msg.Alert(&lt;span class="str"&gt;&amp;quot;Alert&amp;quot;&lt;/span&gt;,
         &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;Hello {0}&amp;quot;&lt;/span&gt;, txtName.Text)
     ).Show();
}&lt;/pre&gt;

&lt;p&gt;Notice that we are using the AjaxEventArgs type for the EventArgs type. This is a special event args that contains a few extra properties that can be of use. Most notably the ExtraParam and ExtraParamnsResponse properties. The former allows you to send this via the Ajax call that may not be contained in controls you can access.&lt;/p&gt;

&lt;p&gt;The final piece of this application is the event mask. This is a very simple operation so we dont really need a mask. Masks are very useful to for stopping the user from interacting with the page or parts of the page while an action is in progress. With Coolite these are easily definable and fit well with the application.&lt;/p&gt;

&lt;p&gt;First add a call to “Thread.Sleep(1000);” to you handler function so that you will get a chance to see the mask we are doing to define. Return to the Button code and update it as such:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnSubmit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Submit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Accept&amp;quot;&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;AjaxEvents&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;Click&lt;/span&gt; &lt;span class="attr"&gt;OnEvent&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnSubmit_Click&amp;quot;&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;EventMask&lt;/span&gt; &lt;span class="attr"&gt;Msg&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Generating Message&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ShowMask&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;Target&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CustomTarget&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;CustomTarget&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;fp1&amp;quot;&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;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;AjaxEvents&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;ext:Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;The two key properties in the &amp;lt;EventMask&amp;gt; tag are &lt;strong&gt;ShowMask&lt;/strong&gt; and &lt;strong&gt;Msg&lt;/strong&gt;.&amp;#160; The former states that when this event is active we do want to show the mask.&amp;#160; The later defines what message the user will see while the event is in progress.&amp;#160; In addition, I have defined the Target as &lt;strong&gt;CustomTarget&lt;/strong&gt; which allows me to specify which section will be grayed out, by default it is the entire page.&amp;#160; In this case I am specifying the control with the ID of “fp1” which is the FormPanel all of this is sitting inside of.&amp;#160; The end result is when you are waiting for the name to come back, your form should look like this:

    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_McWINbq-D3o/SpGtkFp706I/AAAAAAAAAEA/zS8X3dXXB10/s1600-h/image%5B10%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_McWINbq-D3o/SpGtknoEa9I/AAAAAAAAAEE/AyhKpXG7hx8/image_thumb%5B5%5D.png?imgmax=800" width="419" height="243" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;To conclude, this article focused on using AjaxEvents with Buttons and how to control the EventMask.&amp;#160; Remember that you can do a lot more with AjaxEvents as they can be applied to most any control.&amp;#160; You just need to tweak things sometimes and always check your pages that the calls are getting the right state data from the controls.&amp;#160; Most of my testing has been with FormPanels and I have found that things not inside FormLayouts are often not submitted for whatever reason.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;AjaxEvents are a big reason why I enjoy using Coolite with webforms over MVC; because I can take advantage of events are server side code in C# as opposed to writing more JavaScript.&amp;#160; But using these two posts you should understand that your code will not be that different in most cases, regardless of which approach you use. &lt;/span&gt;&lt;/p&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;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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-1351602790115193555?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DiAyaRNYU_NcBIQgfqTwATNOJvQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DiAyaRNYU_NcBIQgfqTwATNOJvQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DiAyaRNYU_NcBIQgfqTwATNOJvQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DiAyaRNYU_NcBIQgfqTwATNOJvQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/OEncoC06ueY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/1351602790115193555/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=1351602790115193555" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/1351602790115193555?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/1351602790115193555?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/OEncoC06ueY/understanding-ajaxevents-in-coolite-asp.html" title="Understanding AjaxEvents in Coolite ASP .NET" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/08/understanding-ajaxevents-in-coolite-asp.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkUGQng_fSp7ImA9WxNSEEk.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-2527800675734376129</id><published>2009-08-23T08:09:00.001-07:00</published><updated>2009-08-23T08:10:23.645-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-23T08:10:23.645-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Implemenation" /><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><category scheme="http://www.blogger.com/atom/ns#" term="Coolite" /><category scheme="http://www.blogger.com/atom/ns#" term="ExtJS" /><title>Getting Started with Coolite on ASP .NET</title><content type="html">&lt;p&gt;I am currently engaged in an opportunity that has taken me to New York to help a client rewrite one of their existing VB6 applications in ASP .NET as a web application.&amp;#160; To aid us with developing this application and provide a very modern and consistent look and feel we are using the &lt;a href="http://www.coolite.com" target="_blank"&gt;Coolite UI Framework&lt;/a&gt; for ASP .NET which leverages the powerful &lt;a href="http://extjs.com" target="_blank"&gt;ExtJS&lt;/a&gt; JavaScript library inside of WebForm controls.&lt;/p&gt;  &lt;p&gt;However, we have found that the the biggest downside to using Coolite is the intense lack of documentation from the creators. This makes it hard to know exactly what we are doing and often leaves us to pull from two or three sites to fully understand what it is capable of.&amp;#160; The biggest help comes from the &lt;a href="http://examples.coolite.com" target="_blank"&gt;Examples&lt;/a&gt; site, and the ExtJS documentation site, since the controls follow the supported properties for those controls. ExtJS has excellent documentation.&amp;#160; But I wanted to talk about Coolite cause I think it has a lot of potential and can really be very helpful if people learn more about it.&amp;#160; So to start this series I am going to give a very basic example of an application which uses Coolite and JavaScript.&amp;#160; So lets get started.&lt;/p&gt;  &lt;p&gt;To begin you will need to download the Coolite binaries from Coolite.com, this will install three binaries (&lt;em&gt;Coolite.Ext.Web.dll, Coolite.Utilities.dll, and Newtonsoft.Json.dll&lt;/em&gt;) and reference these in your solution.&lt;/p&gt;  &lt;p&gt;The second step is to update your web application web.config file to support Coolite in the application.&amp;#160; So first add this line to your web.config after the &lt;strong&gt;last section group.&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configSections&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;sectionGroup&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;section&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;coolite&amp;quot;&lt;/span&gt;
       &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Coolite.Ext.Web.GlobalConfig&amp;quot;&lt;/span&gt;
       &lt;span class="attr"&gt;requirePermission&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&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;configSections&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;coolite&lt;/span&gt; &lt;span class="attr"&gt;idMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Explicit&amp;quot;&lt;/span&gt;
       &lt;span class="attr"&gt;theme&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Default&amp;quot;&lt;/span&gt;
       &lt;span class="attr"&gt;initScriptMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Linked&amp;quot;&lt;/span&gt;
       &lt;span class="attr"&gt;scriptMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Debug&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;Also included in this screen shot is the next step of what to add, and that is the new section as defined by the section definition we just added.&amp;#160; Here you can specify a number of things, but the two things to take note of here are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;idMode&lt;/strong&gt;:&amp;#160; use Explicit here so that Coolite controls can be referenced in JavaScript without worry about naming containers as with typical ASP .NET controls &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;theme&lt;/strong&gt;: defines the UI styles that Coolite will reference for all controls. Can be Default, Gray, Slate &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next thing we have to add are some reference to HTTP handlers and modules; so we add the following lines to the web.config: 
  &lt;br /&gt;

  &lt;br /&gt;To &lt;strong&gt;httpHandlers&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;httpHandlers&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;add&lt;/span&gt; &lt;span class="attr"&gt;path&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;*/coolite.axd&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;verb&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;*&amp;quot;&lt;/span&gt;
     &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Coolite.Ext.Web.ResourceManager&amp;quot;&lt;/span&gt;
     &lt;span class="attr"&gt;validate&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&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;httpHandlers&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;To &lt;strong&gt;httpModules:&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;httpModules&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;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AjaxRequestModule&amp;quot;&lt;/span&gt;
         &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Coolite.Ext.Web.AjaxRequestModule,
                    Coolite.Ext.Web&amp;quot;&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;httpModules&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;Optionally, I like to add the following line to my pages collection in &lt;strong&gt;system.web&lt;/strong&gt; to make referencing the Coolite controls easier:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;pages&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;controls&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;add&lt;/span&gt; &lt;span class="attr"&gt;assembly&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Coolite.Ext.Web&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;namespace&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Coolite.Ext.Web&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;tagPrefix&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ext&amp;quot;&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;controls&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;pages&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;So lets start with building a simple form that will say “Hello {name}” provided a name in a textbox.&amp;#160; I am going to do this using JavaScript on the client side, another blog post will detail doing it with AjaxEvents.&lt;/p&gt;

&lt;p&gt;So lets first show some basic markup that uses Coolite to create a form, this first thing that every page using Coolite controls must have is a ScriptManager to facilitate the inclusion of JavaScript to support the various effects, so: 
  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_McWINbq-D3o/SpFboRRsVRI/AAAAAAAAADo/n1D4NkvdXH4/image10%5B1%5D.png?imgmax=800" width="455" height="337" /&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Next, we will want to create a small form, so we will use a FormPanel control, which gives us a very nice look and feel, so: 
  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_McWINbq-D3o/SpFbpew_P0I/AAAAAAAAADs/v6dZOvCV3jU/image14%5B1%5D.png?imgmax=800" width="459" height="340" /&gt;&lt;/p&gt;

&lt;p&gt;I have defined a lot of properties on the form, here is an explanation for a few of them: &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;FormID: Used in AjaxEvent referencing and to tie controls to certain actions, not really used in this approach, but will be useful when we show AjaxEvents &lt;/li&gt;

  &lt;li&gt;Title: The title displayed for the Form (see next screenshot) &lt;/li&gt;

  &lt;li&gt;ButtonAlign: The alignment of the buttons defined in the FormPanels &amp;lt;Buttons&amp;gt; portion &lt;/li&gt;

  &lt;li&gt;StyleSpec: The style rule to apply to the panel as a whole &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Running this should produce the following UI: 
  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_McWINbq-D3o/SpFbqGBT6SI/AAAAAAAAADw/U8UYcgcSnHM/image25%5B1%5D.png?imgmax=800" width="442" height="265" /&gt; &lt;/p&gt;

&lt;p&gt;Not a bad looking UI considering we haven’t had to do any CSS and this is compatible with IE6 even, so lets keep moving forward and add the actual UI.&lt;/p&gt;

&lt;p&gt;The FormPanel has quite a few internal sections, for this tutorial we will use two of them &amp;lt;Body&amp;gt; and &amp;lt;Buttons&amp;gt;.&amp;#160; Here is the updated code: &lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &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;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:ScriptManager&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ScriptManager1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:FormPanel&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;fp1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="attr"&gt;FormID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;mainForm&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Test Form&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;150&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ButtonAlign&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Right&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="attr"&gt;BodyStyle&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;padding: 10px;&amp;quot;&lt;/span&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="attr"&gt;StyleSpec&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;margin: 10px;&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &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;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:FormLayout&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;frmLayout&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="attr"&gt;LabelSeparator&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot; &amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;LabelAlign&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Left&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Anchor&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:TextField&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;txtName&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;            &lt;span class="attr"&gt;AllowBlank&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;15&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;FieldLabel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:Anchor&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:FormLayout&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &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;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Buttons&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnSubmit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Submit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Accept&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Buttons&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ext:FormPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &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;/pre&gt;
&lt;/div&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;p&gt;&lt;/p&gt;

&lt;p&gt;So what we have done first is the update the body of the FormPanel with a FormLayout.&amp;#160; There are a lot of things that FormLayout does for us, but for new its enough that it will render the elements described in each &amp;lt;ext:Anchor&amp;gt; block vertically with some label text to the left.&lt;/p&gt;

&lt;p&gt;In this case we are adding a a Ext Textfield that has a few things defined:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;AllowBlank – the textbox will validate user input and require input&lt;/li&gt;

  &lt;li&gt;FieldLabel – this is the text of the label that will appear to the left. It can also appear above the control, this controlled by the LabelAlign property (see the FormLayout)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next we move to the &amp;lt;Buttons&amp;gt; group. This section is placed beneath the Panel body and houses button controls, here I am defining a single button.&amp;#160; If you run this, it should output something like this:
  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_McWINbq-D3o/SpFbrD5W8qI/AAAAAAAAAD0/i6rdakRnOOM/image%5B18%5D.png?imgmax=800" width="432" height="252" /&gt;&lt;/p&gt;

&lt;p&gt;The next part of this is to allow the user to click “Submit” and have the program respond with an Ext alert that says “Hello”.&amp;#160; So the first thing we will need is something to listen for this event.&amp;#160; Update the Button definitions as such:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ext:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;btnSubmit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;
  &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Submit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Accept&amp;quot;&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;Listeners&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;Click&lt;/span&gt; &lt;span class="attr"&gt;Fn&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SayHello&amp;quot;&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;Listeners&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;ext:Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;p&gt;There are a number of events that we can listen for, obviously the one that makes the most sense in this case is Click.&amp;#160; So when a click happens we want to call the function &lt;strong&gt;SayHello&lt;/strong&gt;. So here is a look at the &lt;strong&gt;SayHello &lt;/strong&gt;function:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;script language=&lt;span class="str"&gt;&amp;quot;javascript&amp;quot;&lt;/span&gt; type=&lt;span class="str"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt;
    &lt;span class="kwrd"&gt;var&lt;/span&gt; SayHello = &lt;span class="kwrd"&gt;function&lt;/span&gt;() {
        &lt;span class="kwrd"&gt;var&lt;/span&gt; name = txtName.getValue();
        Ext.Msg.alert(&lt;span class="str"&gt;&amp;quot;Alert&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Hello &amp;quot;&lt;/span&gt; + name);
      }
    &amp;lt;/script&amp;gt;&lt;/pre&gt;

&lt;p&gt;Notice how we are getting the value of the text field, we are simply calling its name, no ClientID (in this case).&amp;#160; We are then creating an ExtJS alert window to display the message.&amp;#160; The reason we use this here is that it will provide an alert that is linked to our theme, this way all visual elements have the same appearance.&amp;#160; So clicking the button should do this:
  &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_McWINbq-D3o/SpFbrsU68_I/AAAAAAAAAD4/rSVJSspilis/image%5B17%5D.png?imgmax=800" width="440" height="243" /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;One thing I do want to point out is that this alert window is NOT an alert window.&amp;#160; It &lt;strong&gt;does not block execution&lt;/strong&gt;, it relies on callbacks to execute code after the “OK” click.&amp;#160; It is nothing more than a modal dialog being shown.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So there you have it, that is a very basic application which uses Coolite to perform a very basic function.&amp;#160; The next time around we will describe how to do this using AjaxEvents, which are a very interesting concept and take much of the problems you encounter with MS Ajax out of the picture. &lt;/p&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;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-2527800675734376129?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vLPqP3nGhoZnVJLz_y_Cl58RK3E/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vLPqP3nGhoZnVJLz_y_Cl58RK3E/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vLPqP3nGhoZnVJLz_y_Cl58RK3E/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vLPqP3nGhoZnVJLz_y_Cl58RK3E/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/yGLD07le_ZY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/2527800675734376129/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=2527800675734376129" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/2527800675734376129?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/2527800675734376129?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/yGLD07le_ZY/getting-started-with-coolite-on-asp-net.html" title="Getting Started with Coolite on ASP .NET" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/08/getting-started-with-coolite-on-asp-net.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ICR3o4fSp7ImA9WxNTE0o.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-8909188587416891015</id><published>2009-08-15T14:26:00.001-07:00</published><updated>2009-08-15T14:26:06.435-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-15T14:26:06.435-07:00</app:edited><title>Moving from ASP .NET MVC to ASP .NET Webforms</title><content type="html">&lt;p&gt;It is very common to hear developers talk about successfully switching to MVC and generating much cleaner applications and there is no doubt that using MVC can certainly generate that.&amp;#160; But as with any technology/framework, misusing it can still result in an application with maintainability issues and the need for the developer to make undesirable decisions.&lt;/p&gt;  &lt;p&gt;Such was the case out here in New York where our client had decided to use the MVC framework with the Coolite UI toolset. I am a big believer then when it comes to using the MVC framework one needs to be careful that the toolset you are using also leverages what MVC gives you.&amp;#160; In the case of the project out here, after numerous discussions it was clear that really the way we were approaching the project we were just not going to leverage MVC in a way that would make sense to use it.&amp;#160; In reality, the project would be better off, given the aims, as a Silverlight project, but due to circumstances surrounding the project it was not an option.&lt;/p&gt;  &lt;p&gt;In addition, we had decided to use the &lt;a href="http://www.coolite.com/" target="_blank"&gt;Coolite&lt;/a&gt; control toolkit for UI.&amp;#160; Given the way that Coolite is setup it makes sense to use it with WebForms over MVC.&amp;#160; While you can certainly use MVC with Coolite (as demonstrated by &lt;a href="http://mvc.coolite.com"&gt;http://mvc.coolite.com&lt;/a&gt;) after spending a week developing in MVC with Coolite it became apparent that it didn’t make sense and I felt we were heading for some problems.&amp;#160; I took these problems to the other developers and after some conversation we decided we needed to talk to the client about possibly changing, let me enumerate some of the arguments that were made:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;MVC’s biggest strength is the decoupling of the view from the controller and the lack of reliance on server controls&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;In our case we are not really using this methodology heavily, instead relying more on web services to talk to the database. This due to the other devices that must be able to tie into this system&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Coolite is designed to work with ASP .NET webforms.&amp;#160; Using Coolite with MVC means a large reliance on JavaScript to gather values and perform saves.&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Using Webforms we can use the code behind to leverage .NET in a way that makes sense given the operations we are performing&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;With Webforms we can still use web service method calls to get data from our database.&amp;#160; It also allows use to make WCF calls via code-behind if needed&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The big point that was made here was that we are only talking minimal gain using MVC from a structure standpoint vs. potentially difficult choices in saving and persisting data and leaning very heavily on JavaScript.&amp;#160; In addition, if done properly an ASP .NET Webform app can be just as well organized as an MVC application if done correctly.&amp;#160; I have certainly see it done by some of the best in the industry and I have their experience to lean on in doing this.&amp;#160; I really think this is the best decision, as much as I want to use MVC, I think you just don't gain anything give what we are doing and how we are approaching it.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-8909188587416891015?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rA0sd23wRxL2gA65I94TCPuLrxY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rA0sd23wRxL2gA65I94TCPuLrxY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rA0sd23wRxL2gA65I94TCPuLrxY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rA0sd23wRxL2gA65I94TCPuLrxY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/dNSx6OTCUGE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/8909188587416891015/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=8909188587416891015" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8909188587416891015?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8909188587416891015?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/dNSx6OTCUGE/moving-from-asp-net-mvc-to-asp-net.html" title="Moving from ASP .NET MVC to ASP .NET Webforms" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/08/moving-from-asp-net-mvc-to-asp-net.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0cBR3YzeCp7ImA9WxJaEUU.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-8679524706336491323</id><published>2009-08-01T21:57:00.001-07:00</published><updated>2009-08-01T21:57:36.880-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-01T21:57:36.880-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technical" /><category scheme="http://www.blogger.com/atom/ns#" term="Rant" /><category scheme="http://www.blogger.com/atom/ns#" term="NHibernate" /><title>Repository Pattern (Revisted)</title><content type="html">&lt;p&gt;In the previous tutorial set we looked at the Repository pattern and how one might use it to construct a support framework for Fluent NHibernate.&amp;#160; If you looked at closely you likely realized some very serious and obvious design flaws.&amp;#160; The main thing that I didn't like about it was the use of the derived repositories and the constraints it placed on various user stories.&amp;#160; For example, in order to save related items, or perform read operations, multiple repository instances were needed.&amp;#160; This creates a huge burden on the developer.&amp;#160; What is really needed in this case is a store, that is a single class that provides lazy loaded instances of the other repositories the system supports.&lt;/p&gt;  &lt;p&gt;To begin this process, we first need to generate code.&amp;#160; Our types are not known to use at any point until after a database is read.&amp;#160; To do this we will use T4 templates.&amp;#160; I will blog later on about creating these templates for now we are just working to understand the theory.&lt;/p&gt;  &lt;p&gt;So the idea behind this reorganization is to create a single class that all other repositories work off.&amp;#160; The repository instances for the specific models will need to provide enough extensibility to let developers take control of the save process, but also provide enough out of the box functionality so that it is useful without modification.&lt;/p&gt;  &lt;p&gt;Furthermore, we want to encourage developers to use our single instance so we need to provide a way for their functions to be called in place of our original.&amp;#160; To do this we will use abstract base classes with virtual methods.&amp;#160; By defining a default save method as virtual in the base class we can provide the developer a way to override the function that is automatically called when a Commit is initiated on the store’s objects.&lt;/p&gt;  &lt;p&gt;So the Store is generally in charge of initiating the Commit process via reflection and finding appropriately decorated properties that represent the Repositories.&amp;#160; The commit is only called if the list is deemed to be dirty.&lt;/p&gt;  &lt;p&gt;Each of the derived repositories can only hold objects of certain type, the type must inherit from EntityBase thereby insuring that the object being operated on is an Entity.&amp;#160; Finally the Entity saving, deleting, and updating operations are all handled in a totally database agnostic way by NHibernate under the hood thanks to the mapping generated via Fluent NHibernate.&lt;/p&gt;  &lt;p&gt;So the end result of this process is that using T4 templates we are able to generate the POCO (Plain Old C# Objects) model files, the Fluent Mapping files, the Derived Repository definitions and the generated portion of the Store all automatically.&amp;#160; In addition, we make all classes partial enabling developers to extend them as they see fit.&amp;#160; This gives us a tremendous about of flexibility for developers to customize certain operations.&amp;#160; This model for repository is a little more closer to what the pattern fully intends, though really is more of a Store pattern, similar to what Linq to SQL and Linq to Entities appear to use to great effect.&amp;#160; In coming tutorials I will back track and help you understand how to create a fully functional Repository Store support framework.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-8679524706336491323?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lMiP5JuLEH1dxW-sS04TTIx1I6s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lMiP5JuLEH1dxW-sS04TTIx1I6s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lMiP5JuLEH1dxW-sS04TTIx1I6s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lMiP5JuLEH1dxW-sS04TTIx1I6s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/oEkucaKfCGU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/8679524706336491323/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=8679524706336491323" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8679524706336491323?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/8679524706336491323?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/oEkucaKfCGU/repository-pattern-revisted.html" title="Repository Pattern (Revisted)" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/08/repository-pattern-revisted.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEcGQX4zcCp7ImA9WxJbE0U.&quot;"><id>tag:blogger.com,1999:blog-345842095883056931.post-5104122592597048343</id><published>2009-07-23T13:47:00.000-07:00</published><updated>2009-07-23T13:47:00.088-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-23T13:47:00.088-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Implemenation" /><category scheme="http://www.blogger.com/atom/ns#" term="Reference" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="NHibernate" /><title>Exploring the Repository Pattern (Part 2)</title><content type="html">&lt;p&gt;In the first portion of this article we explored what the Repository pattern is and provided a basic implementation for now developers are using it to facilitate data access.&amp;#160; We create a basic class &lt;strong&gt;RepositoryBase&amp;lt;T, PK&amp;gt; &lt;/strong&gt;and showed a basic example of using it.&amp;#160; Now we will explore this class and demonstrate how to take the Repository further and make it more useful.&lt;/p&gt;  &lt;p&gt;Now, in what we created there is one major obvious drawback.&amp;#160; If we wanted to write a custom query how do we do so?&amp;#160; Surrounding this matter is a lot of debate on extending the pattern, for the most part I have seen the following schools of thought:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Query objects &lt;/li&gt;    &lt;li&gt;Extension methods &lt;/li&gt;    &lt;li&gt;Derived Model Repositories &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Of these I find query objects to be the most fascinating, I will defer to my friend RossCode to explain them &lt;a href="http://www.rosscode.com/blog/index.php?title=the_repository_pattern_andash_iarsquo_m_&amp;amp;more=1&amp;amp;c=1&amp;amp;tb=1&amp;amp;pb=1" target="_blank"&gt;here&lt;/a&gt;.&amp;#160; But essentially the idea is to create a new abstract base class called &lt;strong&gt;QueryBase&amp;lt;T&amp;gt;&lt;/strong&gt; and use this to create objects that contain criteria for performing these custom queries.&amp;#160; Using this we can create two methods (one for singles, one for sets) on our &lt;strong&gt;RepositoryBase&amp;lt;T, PK&amp;gt; &lt;/strong&gt;like such:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; T GetBy(QueryBase&amp;lt;T&amp;gt; query)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;     &lt;span class="kwrd"&gt;return&lt;/span&gt; query.SatisfyingElementFrom(GetAll());&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="rem"&gt;/// Get a listing of records that matches a custom criteria&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;&lt;span class="rem"&gt;/// &amp;lt;param name=&amp;quot;query&amp;quot;&amp;gt;Query object to supply the criteria data&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;&lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;ILIst of T or null&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt; GetAll(QueryBase&amp;lt;T&amp;gt; query)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;     &lt;span class="kwrd"&gt;return&lt;/span&gt; query.SatisfyingElementsFrom(GetAll());&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&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;p&gt;What we have done is create a set of methods that take an abstract type as its parameter, thus allowing any class that inherits from &lt;strong&gt;QueryBase&lt;/strong&gt;.&amp;#160; In reality, this method is designed to be used with something like LINQ to NHibernate which would allow these custom queries to benefit from the deferred execution that is found in many data related variants of Linq, in our example however, we will be using standard Linq to Objects; I believe RossCode’s examples use Linq to NHibernate.&lt;/p&gt;

&lt;p&gt;So using these query objects we can define separate classes for each custom query we wish to make and then pass then to either &lt;em&gt;GetBy &lt;/em&gt;or &lt;em&gt;GetAll&lt;/em&gt;.&amp;#160; This has the advantage of allowing us to use only one class for the repository and yields custom results.&amp;#160; But wait there is a slight problem with this method from a maintenance perspective.&amp;#160; Now we are dropping this query objects all over the application, and while this may be ok for a smaller application, in larger application it could quickly turn into a mess.&amp;#160; From a Separation of Concerns perspective we are not defining our queries outside the data access layer.&amp;#160; The caller should not need to know anything about how the query is generated, only that it can call the function and return the result.&lt;/p&gt;

&lt;p&gt;Lets stick with the idea of Query Objects and address the root of this problem: we want to be able to make the custom calls as dumb as possible and not have query definition logic in the layer making the call.&amp;#160; One of the ways around this is to use extension methods (.NET 3.5).&amp;#160; Consider the following example:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;div class="csharpcode"&gt;
    &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;Episode&amp;gt; GetEpisodes(&lt;/pre&gt;

    &lt;pre&gt;     &lt;span class="kwrd"&gt;this&lt;/span&gt; RepositoryBase&amp;lt;Episode, &lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; repo,&lt;/pre&gt;

    &lt;pre class="alt"&gt;     &lt;span class="kwrd"&gt;bool&lt;/span&gt; state)&lt;/pre&gt;

    &lt;pre&gt;{&lt;/pre&gt;

    &lt;pre class="alt"&gt;     &lt;span class="kwrd"&gt;return&lt;/span&gt; repo.GetAll(&lt;span class="kwrd"&gt;new&lt;/span&gt; ActiveEpisodeQuery(state));&lt;/pre&gt;

    &lt;pre&gt;}&lt;/pre&gt;
  &lt;/div&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;/div&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;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;What this will do is attach a method (&lt;em&gt;GetEpisodes&lt;/em&gt;) onto all instances of &lt;strong&gt;RepositoryBase&amp;lt;Episode, int&amp;gt;&lt;/strong&gt; thus allowing us to contain the method to a single function.&amp;#160; While this is not a bad approach, I do not like it because it feels so awkward; I would rather the functions be part of the class themselves, I cannot call this method through reflection should I need to later on.&lt;/p&gt;

&lt;p&gt;My chosen way is to use derived repository classes, because:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Base classes should always be declared abstract and thus not allowed to be instantiated&lt;/li&gt;

  &lt;li&gt;Using a derived class allows the ability to hide more from the developer and make their paths less cluttered&lt;/li&gt;

  &lt;li&gt;It builds on the OO principle of encapsulation and allows us to change things at will&lt;/li&gt;

  &lt;li&gt;Using inheritance from the gives us the ability to hide things we may not need thus creating a simpler API&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The major drawback to this approach is that you end up having to create and maintain more classes, because now every model will need to have a specific Repository class.&amp;#160; A sample one could look like such:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; EpisodeRepository :&lt;/pre&gt;

  &lt;pre&gt;     RepositoryBase&amp;lt;Episode, &lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;{&lt;/pre&gt;

  &lt;pre&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;Episode&amp;gt; GetActiveEpisodes()&lt;/pre&gt;

  &lt;pre class="alt"&gt;     {&lt;/pre&gt;

  &lt;pre&gt;          &lt;span class="kwrd"&gt;return&lt;/span&gt; GetAll(&lt;span class="kwrd"&gt;new&lt;/span&gt; ActiveEpisodeQuery(&lt;span class="kwrd"&gt;true&lt;/span&gt;));&lt;/pre&gt;

  &lt;pre class="alt"&gt;     }&lt;/pre&gt;

  &lt;pre&gt;}&lt;/pre&gt;
&lt;/div&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;p&gt;Using this approach you can increase the amount of code that can be encapsulated inside the derived class and thus perform more complex operations on the repository objects, all while providing a simple API to the outside.&lt;/p&gt;

&lt;p&gt;To conclude, we talked about the major shortcoming of the basic form of the Repository pattern: customization.&amp;#160; In any data driven application you will need to create custom queries that mutate and translate data in different ways.&amp;#160; The use of query objects can greatly enhance the clarity of the underlying logic, but without an additional layer of abstraction could pose great problems for code maintenance. To mitigate this we analyzed two possible approaches: 1) use extension methods to extend possible instantiations 2) create derived repositories for models to provide these custom data manipulations methods.&lt;/p&gt;

&lt;p&gt;It is my personal preference to use approach #2 as it enables you to achieve complex operations with a much simpler interface.&amp;#160; It also helps with code maintenance and readability as the code can describe to the developer what it is doing and what is involved in the operation.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/345842095883056931-5104122592597048343?l=www.jfarrell.net' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/p6BTBXIh0PfkvGDwa2Ea02qmBl8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p6BTBXIh0PfkvGDwa2Ea02qmBl8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/p6BTBXIh0PfkvGDwa2Ea02qmBl8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p6BTBXIh0PfkvGDwa2Ea02qmBl8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/jfarrell/cdrx/~4/hxRi7JilrrQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.jfarrell.net/feeds/5104122592597048343/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=345842095883056931&amp;postID=5104122592597048343" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5104122592597048343?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/345842095883056931/posts/default/5104122592597048343?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jfarrell/cdrx/~3/hxRi7JilrrQ/exploring-repository-pattern-part-2.html" title="Exploring the Repository Pattern (Part 2)" /><author><name>xximjasonxx</name><uri>http://www.blogger.com/profile/07730569753432545996</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="03312082082897193843" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.jfarrell.net/2009/07/exploring-repository-pattern-part-2.html</feedburner:origLink></entry></feed>
