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

<channel>
	<title>Brian J. Cardiff &#187; MSP</title>
	<atom:link href="http://weblogs.manas.com.ar/bcardiff/category/msp/feed/" rel="self" type="application/rss+xml" />
	<link>http://weblogs.manas.com.ar/bcardiff</link>
	<description>Keep in touch</description>
	<lastBuildDate>Fri, 24 Jul 2009 12:27:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>RUN09: Jugando dentro del browser: AJAX Client Templates y jQuery en ASP.NET</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2009/03/run09-jugando-dentro-del-browser-ajax-client-templates-y-jquery-en-aspnet/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2009/03/run09-jugando-dentro-del-browser-ajax-client-templates-y-jquery-en-aspnet/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 00:39:00 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[MSP]]></category>
		<category><![CDATA[Talks]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=58</guid>
		<description><![CDATA[Martín Salías and I participated at RUN09. The talk was named &#8220;Jugando dentro del browser: AJAX Client Templates y jQuery en ASP.NET&#8221;. We had the chance to show how Microsoft Ajax Client Templates works with JsonResult of ASP.NET MVC and jQuery datepicker plugin. You can download the source code of the demo: run09-b1-sourcecode Here are the resources [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.salias.com.ar/">Martín Salías</a> and I participated at <a href="http://www.puertadeenlace.net/run09/">RUN09</a>. The talk was named &#8220;Jugando dentro del browser: AJAX Client Templates y jQuery en ASP.NET&#8221;. We had the chance to show how <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24887">Microsoft Ajax Client Templates</a> works with JsonResult of <a href="http://www.asp.net/mvc/">ASP.NET MVC</a> and <a href="http://jquery.com/">jQuery</a> <a href="http://jqueryui.com/demos/datepicker/">datepicker plugin</a>.</p>
<p>You can download the source code of the demo: <a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/03/run09-b1-sourcecode.zip">run09-b1-sourcecode</a></p>
<p>Here are the resources we suggest to get started with all this:</p>
<ul>
<li><a href="http://www.asp.net/mvc">http://www.asp.net/mvc</a></li>
<li><a href="http://www.codeplex.com/aspnet">http://www.codeplex.com/aspnet</a></li>
<li><a href="http://jquery.com">http://jquery.com</a></li>
<li><a href="http://www.codeplex.com/nerddinner">http://www.codeplex.com/nerddinner</a></li>
<li><a href="http://weblogs.asp.net/bleroy">http://weblogs.asp.net/bleroy</a></li>
<li><a href="http://weblogs.asp.net/infinitiesloop">http://weblogs.asp.net/infinitiesloop</a></li>
<li><a href="http://delicious.com/msalias/run09">http://delicious.com/msalias/run09</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2009/03/run09-jugando-dentro-del-browser-ajax-client-templates-y-jquery-en-aspnet/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Guidelines: Notifications</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2009/03/aspnet-mvc-guidelines-notifications/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2009/03/aspnet-mvc-guidelines-notifications/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 14:42:23 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[MSP]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=49</guid>
		<description><![CDATA[While developing a web application a developer should build some infrastructure for the whole system. ASP.NET MVC is not the exception. The fact that ASP.NET MVC is a framework, it doesn&#8217;t mean that covers 100% of the necessity a developer will have during the development, but it should let you fill the gap. This gap [...]]]></description>
			<content:encoded><![CDATA[<p>While developing a web application a developer should build some infrastructure for the whole system. <a href="http://www.asp.net/mvc/" target="_blank">ASP.NET MVC</a> is not the exception. The fact that <a href="http://www.asp.net/mvc/" target="_blank">ASP.NET MVC</a> is a framework, it doesn&#8217;t mean that covers 100% of the necessity a developer will have during the development, but it should let you fill the gap. This gap could be filled by third party libraries or just by something ad-hoc you develop.</p>
<p>I saw (and develop) some kind of notifications solutions in order to tell the user that something (good or bad) have just happened due to his action eg.: &#8220;your password has been changed&#8221;, &#8220;you have new messages&#8221;, etc. These implementations were constrained to the MVC-way, letting the model has a notification property, letting the view show that property, etc. They could, but as soon as you reach some <a href="http://blog.eworldui.net/post/2008/05/ASPNET-MVC---Using-Post2c-Redirect2c-Get-Pattern.aspx" target="_blank">Post-Redirect-Get</a>, or <strong>some partial page AJAX</strong> call, or <strong>JSON AJAX</strong> call you will get into troubles.</p>
<p>Along this post I will show a notification solution that play nice with all these scenarios with a unify way. I don&#8217;t I&#8217;m telling something new here, just sharing the experience and thuoghts. I will assume that the notifications are plain strings, but it could be extended to include a kind field (info, warning, error).</p>
<p>Download <a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/03/mvcguidelines.zip">sample code</a> for <a href="http://go.microsoft.com/fwlink/?LinkId=144443" target="_blank">ASP.NET MVC RC 2</a>. Try test buttons and changing your password.</p>
<h3>Interface</h3>
<p>The first thing is how we expect to leave a notification. Since the notification capability should be used a lot I prefer to make them available without needing to change the <strong>Model</strong> or <strong>ActionResult</strong>, so lets create a <strong>INotificationService</strong>. In order to play nice with designs and testing prefer to let the controllers get a reference to:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">interface</span> INotificationService
{
    <span class="kwrd">void</span> Send(<span class="kwrd">string</span> message);
}</pre>
<style type="text/css">.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; }
</style>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<h3>How to use it</h3>
<p>All the controllers should have <strong>HandleNotificationAttribute</strong> applied, later we will see what is this for. The controller that want to send a notification will need to get a reference to an <strong>INotificationService</strong>. During the execution of the action, the method <strong>Send</strong> could be called as many times as you want. You are able to return what ever <strong>ActionResult</strong> you want. But if doing a redirect, be sure to use a <strong>RedirectToRouteResult</strong> (i.e. suggesting <a href="http://asp.net/mvc" target="_blank">ASP.NET MVC</a> way to send HTTP Redirects).</p>
<pre class="csharpcode">[HandleNotification]
<span class="kwrd">public</span> <span class="kwrd">class</span> SomeController : Controller
{
    INotificationService notification;

    <span class="kwrd">public</span> SomeController(INotificationService notification)
    {
        <span class="kwrd">this</span>.notification = notification;
    }

    <span class="kwrd">public</span> ViewResult Index()
    {
        notification.Send(<span class="str">"Welcome!"</span>);
        <span class="rem">// Create some model for the view</span>
        <span class="kwrd">return</span> View();
    }

    <span class="kwrd">public</span> ActionResult RedirectCall()
    {
        <span class="rem">// Perform changes</span>
        notification.Send(<span class="str">"data saved"</span>);
        <span class="kwrd">return</span> RedirectToAction(<span class="str">"Index"</span>, <span class="str">"Home"</span>);
    }

    <span class="kwrd">public</span> JsonResult JsonAjaxCall()
    {
        notification.Send(<span class="str">"Lorem ipsum"</span>);
        notification.Send(<span class="str">"dolor sit amet"</span>);
        <span class="kwrd">return</span> Json(<span class="kwrd">new</span> { A = 1, B = <span class="str">"lorem"</span> });
    }

}</pre>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>As it can be seen, it is straight forward the usage. The <strong>INotificationService</strong> only expose a method to add notification, but not to clear them.</p>
<h3>Client side</h3>
<p>Just for encapsulation I choose to create a <strong>ViewUserControl</strong> that it should be included at the <strong>MasterPage</strong>, or at every respose page of a non-AJAX HTTP Request.</p>
<pre class="csharpcode"><span class="asp">&lt;%@ Master ... %&gt;</span>
<span class="asp">&lt;%@ Register TagPrefix="core" TagName="notifications"
    Src="~/Core/Notifications/ShowNotifications.ascx" %&gt;</span>
<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> <span class="kwrd">...</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">="http://www.w3.org/1999/xhtml"</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!-- ... --&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">core:notifications</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="rem">&lt;!-- ... --&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>The client side use Javascript to display notification, in the sample below I use <a href="http://www.stanlemon.net/projects/jgrowl.html" target="_blank">jGrowl</a> (and <a href="http://jquery.com/" target="_blank">jQuery</a>). It is easy to change it to generate some just plain divs inside an identified element if you prefer.</p>
<p>Somewhere in the code of <strong>ShowNotifications.ascx</strong> the following code defines how a notification is shown:</p>
<pre class="csharpcode"><span class="kwrd">function</span> showNotification(msg) {
    $.jGrowl(msg);
}</pre>
<p>The <strong>HandleNotificationAttribute</strong> has the responsibility to expose the recent notifications in the way the <strong>ShowNotifications.ascx</strong> is expecting them.</p>
<p>The following section goes trough implementation details, which is not the most interesting part in the article.</p>
<h3>How it works</h3>
<p>I will detail how each scenarios is supported:</p>
<h4>non-AJAX/non-redirect Actions</h4>
<p>The action have just store some notifications. The <strong>HandleNotificationAttribute</strong> add to the <strong>ViewData</strong> a <strong>HandleNotificationInfo</strong> that the <strong>ShowNotifications.ascx</strong> will use to render some calls to the <strong>showNotification</strong> functions.</p>
<h4>AJAX Actions (JSON or Partial View)</h4>
<p>The JSON calls force us to send the notification out-of-the-band, I choose to use cookies. So, if the <strong>HandleNotificationInfo</strong> detects that the request is an AJAX request, it serialize the <strong>HandleNotificationInfo</strong> using JSON. The <strong>ShowNotifications.ascx</strong> attach to <a href="http://docs.jquery.com/Ajax/ajaxComplete" target="_blank">AJAX Complete event</a> (using jQuery) and pulls recently added cookie, and remove it.</p>
<p>Up to this point the storage of the notifications (<strong>INotificationRepository</strong>) could be implemented inside the request life cycle, but in order to support the next scenario we will use an implementation of <strong>INotificationRepository</strong> that use the HTTP Session object.</p>
<h4>Post-Redirect-Get</h4>
<p>When the action tells the <strong>INotificationService</strong> to send a notification, it is stored (as in every call) using the <strong>INotificationRepository</strong>. In this case, the <strong>HandleNotification</strong> performs no action, remember it was a POST request. The client receives a Redirect which performs a GET that will fall in the previous cases. Since the <strong>INotificationRepository</strong> use HTTP Session object, upon the action executed by the GET is completed, the <strong>HandleNotification</strong> will perform the usual task: pop the stored notifications in <strong>INotificationRepository</strong> and expose them to the client.</p>
<p>A final remark is that since Attributes can&#8217;t be injected with dependencies I expose a static property that is set upon Application_Start, in <strong>Global.asax</strong>.</p>
<p>Hope you find it useful. I&#8217;m more interesting in the overall solution than in the actual implementation: that is, enhancing the <a href="http://asp.net/mvc" target="_blank">ASP.NET MVC</a> framework with some services you would need for a better application development.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2009/03/aspnet-mvc-guidelines-notifications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Latam Windows Day &#8211; El futuro de la plataforma de desarrollo Web hoy</title>
		<link>http://weblogs.manas.com.ar/bcardiff/2009/03/latam-windows-day-el-futuro-de-la-plataforma-de-desarrollo-web-hoy/</link>
		<comments>http://weblogs.manas.com.ar/bcardiff/2009/03/latam-windows-day-el-futuro-de-la-plataforma-de-desarrollo-web-hoy/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 13:51:09 +0000</pubDate>
		<dc:creator>bcardiff</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[MSP]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/bcardiff/?p=38</guid>
		<description><![CDATA[Today is the Windows Day event. With Sergio we are presenting some new features that will be part of ASP.NET 4.0 and other stuff: ASP.NET MVC Dynamic Data Client Templates IE Developers Tools jQuery First of  all a disclaimer is mandatory, the session was recorded during January, and as expected some improvements happened since that [...]]]></description>
			<content:encoded><![CDATA[<p>Today is the <a href="http://www.microsoft.com/latam/windowsday/">Windows Day event</a>. With <a href="http://weblogs.manas.com.ar/smedina">Sergio</a> we are presenting some new features that will be part of ASP.NET 4.0 and other stuff:</p>
<ul>
<li>ASP.NET MVC</li>
<li>Dynamic Data</li>
<li>Client Templates</li>
<li>IE Developers Tools</li>
<li>jQuery</li>
</ul>
<p>First of  all a disclaimer is mandatory, the session was recorded during January, and as expected some improvements happened since that day:</p>
<ol>
<li>ASP.NET MVC move from Beta to RC (and to RC Refresh)</li>
<li>IE8 move from Beta to RC</li>
<li>jQuery move from 1.2.6 to 1.3.2 (with a brand new jQuery UI)</li>
</ol>
<p>One the my preferred slides is the one where we compare ASP.NET WebForms with ASP.NET MVC:</p>
<table border="0">
<tbody>
<tr>
<th></th>
<th>ASP.NET MVC</th>
<th>ASP.NET WebForms</th>
</tr>
<tr>
<td>URLs</td>
<td>/Users/jdoe</td>
<td>/UserProfile.aspx?id=jdoe</td>
</tr>
<tr>
<td>Testing</td>
<td>straightforward</td>
<td>not so easy</td>
</tr>
<tr>
<td>Markup</td>
<td>full control</td>
<td>always ViewState</td>
</tr>
<tr>
<td>User actions</td>
<td>HTTP Request</td>
<td>PostBacks</td>
</tr>
<tr>
<td>Request Life Cycle</td>
<td>M &#8211; V &#8211; C</td>
<td>PageLifeCycle</td>
</tr>
<tr>
<td>Integration with jQuery, Protoype, etc.</td>
<td>100%</td>
<td>some dificulties</td>
</tr>
<tr>
<td>AJAX</td>
<td>grained control</td>
<td>UpdatePanel</td>
</tr>
</tbody>
</table>
<p>This shows which thing you should have in mind if you are coming from WebForms in order to have a smooth transition to MVC.</p>
<p>Here are some resources:</p>
<ul>
<li><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/03/el-futuro-de-la-plataforma-de-desarrollo-web-hoy.pdf">Slides [757 KB]</a></li>
<li><a href="http://weblogs.manas.com.ar/bcardiff/wp-content/uploads/2009/03/todolist-sourcecode.zip">TODO list demo (Source Code) [648 KB]<br />
</a></li>
</ul>
<p>Sergio will post in <a href="http://weblogs.manas.com.ar/smedina">his blog</a> the other demo.</p>
<p>You can leave comments and questions in this post or <a href="http://200.58.118.10/post/Sesion-MSDN-2El-futuro-de-la-plataforma-de-desarrollo-Web-hoy.aspx">the one in windows day blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/bcardiff/2009/03/latam-windows-day-el-futuro-de-la-plataforma-de-desarrollo-web-hoy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
