<?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>Tim Van Wassenhove &#187; ASP.NET</title>
	<atom:link href="http://www.timvw.be/category/information-technology/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.timvw.be</link>
	<description>The journey of a thousand miles begins with one step.</description>
	<lastBuildDate>Thu, 29 Jul 2010 17:07:31 +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>Easy pattern for Control state</title>
		<link>http://www.timvw.be/easy-pattern-for-control-state/</link>
		<comments>http://www.timvw.be/easy-pattern-for-control-state/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 17:32:03 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.timvw.be/?p=1531</guid>
		<description><![CDATA[If you have decided that your WebControl requires to maintain it&#8217;s state you will want to figure out how to implement Control state. Most examples on the web will then create an array of objects and then hardcode the indices to find stuff back&#8230; Simply define a serializable inner class and use that instead of [...]]]></description>
			<content:encoded><![CDATA[<p>If you have decided that your WebControl requires to maintain it&#8217;s state you will want to figure out how to implement Control state. Most examples on the web will then create an array of objects and then hardcode the indices to find stuff back&#8230; Simply define a serializable inner class and use that instead of the &#8216;magic array object&#8217;. Eg:</p>

<pre class="brush: csharp;">class SilverlightHost : WebControl
{
 [Serializable]
 class State
 {
  public object BaseState { get; set; }
  public string SilverlightUrl { get; set; }
  public string SilverlightErrorHandlerUrl { get; set; }
  public Dictionary&lt;string, string&gt; Parameters { get; set; }
 }

 protected override void OnInit(EventArgs e) 
 {
  base.OnInit(e);
  Page.RegisterRequiresControlState(this);
 }

 protected override object SaveControlState()
 {
  var state = new State
  {
   BaseState = base.SaveControlState(),
   SilverlightUrl = SilverlightUrl,
   SilverlightErrorHandlerUrl = SilverlightErrorHandlerUrl,
   Parameters = parameters
  };
  return state;
 }

 protected override void LoadControlState(object savedState)
 {
  var state = (State)savedState;
  SilverlightUrl = state.SilverlightUrl;
  SilverlightErrorHandlerUrl = state.SilverlightErrorHandlerUrl;
  parameters = state.Parameters;
  base.LoadControlState(state.BaseState);
 }
}</pre>]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/easy-pattern-for-control-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exploring AJAX on the ASP.NET platform</title>
		<link>http://www.timvw.be/exploring-ajax-on-the-aspnet-platform/</link>
		<comments>http://www.timvw.be/exploring-ajax-on-the-aspnet-platform/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 15:50:04 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://www.timvw.be/?p=752</guid>
		<description><![CDATA[I finally found some time to experiment with AJAX on the ASP.NET platform. The first technique i looked into was Partial-Page Rendering with controls like UpdatePanel. It gave me an awkward feeling but even Dino Esposito, who spent a whole chapter on this technique in his book, seems to share that feeling. Page methods, public [...]]]></description>
			<content:encoded><![CDATA[<p>I finally found some time to experiment with AJAX on the ASP.NET platform. The first technique i looked into was <a href="http://msdn.microsoft.com/en-us/library/bb386573.aspx">Partial-Page Rendering</a> with controls like <a href="http://msdn.microsoft.com/en-us/library/bb386454.aspx">UpdatePanel</a>. It gave me an awkward feeling but even Dino Esposito, who spent a whole chapter on this technique in his <a href="http://www.amazon.com/Programming-Microsoft-ASP-NET-Dino-Esposito/dp/0735625271">book</a>, seems to <a href="http://weblogs.asp.net/despos/archive/2007/09/19/partial-rendering-misses-ajax-architectural-points.aspx">share</a> that feeling.</p>

<p>Page methods, public static methods that are decorated with the <a href="http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.aspx">WebMethodAttribute</a> declared on a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.aspx">Page</a> are exposed as a WebService method and return the result as <a href="http://www.json.org/">JSON</a>. An easy solution but it comes with the cost that it does not offer much flexibility.</p>

<p>Thanks to the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx">WebHttpBinding</a> and <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.aspx">WebInvokeAttribute</a> the <a href="http://msdn.microsoft.com/en-us/library/ms735119.aspx">Windows Communication Foundation</a> now supports services that return JSON in a <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>full call style. This is the technique that i prefer.</p>

<p><a href="http://jquery.com/">jQuery</a> is a very sweet library that simplifies JavaScript  development seriously and provides an easy way to consume WCF/JSON services easily. Here is an example of a page with a button that by default triggers a postback (supporting all users, even those without JavaScript) but that behavior is overriden with a XMLHTTP request instead once the document is loaded (an enhancement for users with JavaScript):</p>

<pre class="brush: jscript;">$(document).ready(function() {
 $('#RequestEchoButton').click(function() {
  $.ajax({
   type: 'POST',
   url: 'Default.svc/Echo',
   data: '{}',
   contentType: 'application/json; charset=utf-8',
   dataType: 'json',
   success: function(data) {
    $('#EchoResultDiv').html(data);
   },
   error: function(data) {
    $('#EchoResultDiv').html('Failed to request Echo.');
   }
  });
  return false;
 });
});</pre>

<p>Notice that my Default.svc page uses the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.webservicehostfactory.aspx">WebServiceHostFactory</a>:</p>

<pre class="brush: xml;">&lt;%@ ServiceHost 
 Language=&quot;C#&quot; 
 Debug=&quot;true&quot; 
 Service=&quot;PageServices.Default&quot;
 Factory=&quot;System.ServiceModel.Activation.WebServiceHostFactory&quot; 
%&gt;</pre>

<p>Conclusion: Unlike jQuery and WCF, I am not convinced that controls like UpdatePanel and ScriptManager add any value to my toolkit.</p>]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/exploring-ajax-on-the-aspnet-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How does the controller know which action method to invoke?</title>
		<link>http://www.timvw.be/how-does-the-controller-know-which-action-method-to-invoke/</link>
		<comments>http://www.timvw.be/how-does-the-controller-know-which-action-method-to-invoke/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 05:46:08 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.timvw.be/?p=696</guid>
		<description><![CDATA[Yesterday i attended another great VISUG event on ASP.NET presented by Maarten Balliauw. He demonstrated a custom filter but did not dig into the mechanics of action method resolving. With the aid of of the ActionName attribute we can map different methods to the same action. The following methods will all map to the same [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday i attended another great <a href="http://www.visug.be">VISUG</a> event on ASP.NET presented by <a href="http://blog.maartenballiauw.be/">Maarten Balliauw</a>. He demonstrated a custom filter but did not dig into the mechanics of action method resolving. With the aid of of the ActionName attribute we can map different methods to the same action. The following methods will all map to the same &#8220;Detail&#8221; action:</p>

<pre class="brush: csharp;">public ActionResult Detail(int productId) { ... }
public ActionResult Detail(int productId, string name) { ... }
[ActionName(&quot;Detail&quot;)] public ActionResult DisplayDetail(int productId) { ... }
[ActionName(&quot;Detail&quot;)] public ActionResult ModifyDetail(int productId, string name) { ... }</pre> 

<p>So how does the Controller know which method to invoke? The answer can be found in the ActionMethodSelector which tries to find the method as following:</p>

<pre class="brush: csharp;">public MethodInfo FindActionMethod(ControllerContext controllerContext, string action) 
{
 List&lt;MethodInfo&gt; methodsMatchingName = GetMatchingAliasedMethods(controllerContext, action);
 methodsMatchingName.AddRange(NonAliasedMethods[action]);
 List&lt;MethodInfo&gt; finalMethods = RunSelectionFilters(controllerContext, methodsMatchingName);

 switch (finalMethods.Count) 
 {
  case 0: return null;
  case 1: return finalMethods[0];
  default: throw CreateAmbiguousMatchException(finalMethods, action);
 }
}</pre>

<p>In the RunSelectionFilters method all the found ActionSelection Attributes have their IsValidForRequest method called in the hope that only one potential method remains.</p>

<p>The most common scenario is that we want our controller to behave depending upon the request method (POST vs GET). For this scenario there is the AcceptVerbsAttribute. eg:</p>

<pre class="brush: csharp;">[ActionName(&quot;Detail&quot;)]
[AcceptVerbs(&quot;GET&quot;)]
public ActionResult DisplayDetail(int productId) { ... }

[ActionName(&quot;Detail&quot;)]
[AcceptVerbs(&quot;POST&quot;)]
public ActionResult ModifyDetail(int productId, string name) { ... }</pre> 

<p>The implementation of the IsValidForRequest method in the AcceptVerbsAttribute is pretty simple:</p>

<pre class="brush: csharp;">public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) 
{
 if (controllerContext == null) throw new ArgumentNullException(&quot;controllerContext&quot;);

 string incomingVerb = controllerContext.HttpContext.Request.HttpMethod;
 return Verbs.Contains(incomingVerb, StringComparer.OrdinalIgnoreCase);
}</pre>]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/how-does-the-controller-know-which-action-method-to-invoke/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adaptive control behavior: LinkButton without javascript</title>
		<link>http://www.timvw.be/adaptive-control-behavior-linkbutton-without-javascript/</link>
		<comments>http://www.timvw.be/adaptive-control-behavior-linkbutton-without-javascript/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 15:06:08 +0000</pubDate>
		<dc:creator>timvw</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.timvw.be/?p=688</guid>
		<description><![CDATA[&#8216;Experiment with Adaptive Control Behavior&#8216; has been an item on my TO-DO list for a very long time and this weekend i finally found some time to do exactly that. Because i hate it that a LinkButton renders as &#60;a href=&#8221;javascript:__doPostBackxxx&#8221;&#62; i decided to develop a ControlAdapter that makes the LinkButton work without JavaScript. While [...]]]></description>
			<content:encoded><![CDATA[<p>&#8216;Experiment with <a href="http://msdn.microsoft.com/en-us/library/67276kc5.aspx">Adaptive Control Behavior</a>&#8216; has been an item on my TO-DO list for a very long time and this weekend i finally found some time to do exactly that. Because i hate it that a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx">LinkButton</a> renders as &lt;a href=&#8221;javascript:__doPostBackxxx&#8221;&gt; i decided to develop a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.adapters.controladapter.aspx">ControlAdapter</a> that makes the LinkButton work without JavaScript. While i was at it i also wrote adapters for the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginstatus(VS.80).aspx">LoginStatus</a> and <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.aspx">Login</a> controls. Feel free to play with the <a href="http://www.timvw.be/wp-content/code/csharp/AdaptiveRenderingDemo.zip">Adaptive Rendering Demo</a>.]]></content:encoded>
			<wfw:commentRss>http://www.timvw.be/adaptive-control-behavior-linkbutton-without-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
