<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4681772286990545567</id><updated>2011-09-28T20:28:53.265+02:00</updated><category term='C#'/><category term='Extenders'/><category term='WP7'/><category term='Topshelf'/><category term='Kayak'/><category term='OWIN'/><category term='FakeItEasy'/><category term='Javascript'/><category term='Ajax'/><category term='Asp.Net'/><title type='text'>HCanber - Thoughts, Tutorials, Tips and Tricks</title><subtitle type='html'>Thoughts, Tips and Tricks on what I'm currently do for a living. I have a &lt;a href="http://hockeswe.blogspot.com/"&gt;Swedish version&lt;/a&gt; of this blog as well.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-2643017005105937356</id><published>2011-09-23T14:15:00.001+02:00</published><updated>2011-09-23T14:15:43.619+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Topshelf'/><title type='text'>Using the Topshelf Shelving Bootstrapper in a Console App</title><content type='html'>&lt;p&gt;&lt;strong&gt;Note!&lt;/strong&gt; This was written for Topshelf 2.2.2.0 and things might have changed in newer versions.&lt;/p&gt;  &lt;h2&gt;Topshelf&lt;/h2&gt;  &lt;p&gt;Topshelf (&lt;a href="http://topshelf-project.com/"&gt;&lt;font color="#0066cc"&gt;http://topshelf-project.com&lt;/font&gt;&lt;/a&gt;) is a framework for building Windows services. The service can either be standalone or one that is hosted by Topshelf. The latter style is called &lt;a href="http://topshelf-project.com/documentation/shelving/"&gt;shelving&lt;/a&gt; (and the service you write is called a shelf) and it enables xcopy deploy of your service, instead of stop service, uninstall, copy, install, start.&lt;/p&gt;  &lt;h2&gt;Debugging a shelf&lt;/h2&gt;  &lt;p&gt;The problem with using the shelving style for your service is debugging. The documentation explains how to do it (&lt;a href="http://topshelf-project.com/debugging-a-topshelf-shelf/"&gt;http://topshelf-project.com/debugging-a-topshelf-shelf/&lt;/a&gt;), but it’s not that neat as it involves modifying where your build outputs the dlls.&lt;/p&gt;  &lt;p&gt;An easier way, at least for me, would be to debug the shelf service by starting it from a console app, i.e. as a standalone service, without any need to modify where the output from the build goes. Ideally the console app would be as simple as possible, just reusing the code from the shelf. &lt;/p&gt;  &lt;p&gt;A shelf service is initiated and configured by a bootstrapper (a class that inherits the interface &lt;code&gt;Bootstrapper&amp;lt;T&amp;gt;&lt;/code&gt;) but unfortunately, if you compare the configuration for a &lt;a href="http://topshelf-project.com/documentation/getting-started/"&gt;standalone service&lt;/a&gt; with the &lt;a href="http://topshelf-project.com/documentation/shelving/"&gt;shelf bootstrapper&lt;/a&gt;, they are not configured the same way, so reusing the configuration from the shelf bootstrapper in a standalone service seems not possible, but it’s actually quite easy.&lt;/p&gt;  &lt;h2&gt;Reuse the bootstrapper&lt;/h2&gt;  &lt;p&gt;Instead of implementing &lt;code&gt;Bootstrapper&amp;lt;T&amp;gt;&lt;/code&gt; derive from this class instead:&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&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; BootstrapperBase&amp;lt;T&amp;gt; : Bootstrapper&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;
{
  &lt;span class="kwrd"&gt;void&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Bootstrapper&lt;/span&gt;&amp;lt;T&amp;gt;.InitializeHostedService(IServiceConfigurator&amp;lt;T&amp;gt; cfg)
  {
    InitializeHostedService(cfg);
  }

  &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; InitializeHostedService(ServiceConfigurator&amp;lt;T&amp;gt; cfg);
}&lt;/pre&gt;

&lt;p&gt;Instead of implementing 
  &lt;br /&gt;&lt;code&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; InitializeHostedService(IServiceConfigurator&amp;lt;T&amp;gt;&lt;t&gt; cfg)&lt;/code&gt; 

  &lt;br /&gt;you implement

  &lt;br /&gt;&lt;font face="Courier New"&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; InitializeHostedService(ServiceConfigurator&amp;lt;T&amp;gt;&lt;t&gt; cfg)&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The bootstrapper in the example at &lt;a href="http://topshelf-project.com/documentation/shelving/"&gt;&lt;font color="#0066cc"&gt;http://topshelf-project.com/documentation/shelving/&lt;/font&gt;&lt;/a&gt; becomes (changes are highlighted)&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AShelvedClockBootstrapper :
      &lt;span style="background: #ff0"&gt;BootstrapperBase&lt;/span&gt;&amp;lt;TheClock&amp;gt;
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span style="background: #ff0" class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InitializeHostedService(&lt;span style="background: #ff0"&gt;ServiceConfigurator&lt;/span&gt;&amp;lt;TheClock&amp;gt; cfg)
  {
    cfg.&lt;span style="background: #ff0"&gt;ConstructUsing&lt;/span&gt;(n =&amp;gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; TheClock());
    cfg.WhenStarted(s =&amp;gt;
    {
      XmlConfigurator.Configure(&lt;span class="kwrd"&gt;new&lt;/span&gt; FileInfo(Path.Combine(
                      AppDomain.CurrentDomain.BaseDirectory,
                      &lt;span class="str"&gt;&amp;quot;clock.log4net.config&amp;quot;&lt;/span&gt;)));
      s.Start();
    });
    cfg.WhenStopped(s =&amp;gt; s.Stop());
  }
}&lt;/pre&gt;

&lt;p&gt;In the console app you start the service like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&amp;#160;&lt;span style="color: blue"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[] args)
{
  &lt;span style="color: #2b91af"&gt;XmlConfigurator&lt;/span&gt;.ConfigureAndWatch(&lt;span style="color: blue"&gt;new&lt;/span&gt;&amp;#160;&lt;span style="color: #2b91af"&gt;FileInfo&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;.\\log4net.config&amp;quot;&lt;/span&gt;));
 
  &lt;span style="color: #2b91af"&gt;HostFactory&lt;/span&gt;.Run(x =&amp;gt;
  {
    x.Service&amp;lt;&lt;span style="color: #2b91af"&gt;TheClock&lt;/span&gt;&amp;gt;(&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; s =&amp;gt; &lt;span style="color: blue"&gt;new&lt;/span&gt;&amp;#160;&lt;span style="color: #2b91af"&gt;AShelvedClockBootstrapper&lt;/span&gt;().InitializeHostedService(s));
    x.RunAsLocalSystem();&amp;#160;&amp;#160; x.SetServiceName(&lt;span style="color: #a31515"&gt;&amp;quot;TheClock&amp;quot;&lt;/span&gt;);
  });
}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-2643017005105937356?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/2643017005105937356/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=2643017005105937356' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/2643017005105937356'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/2643017005105937356'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2011/09/using-topshelf-shelving-bootstrapper-in.html' title='Using the Topshelf Shelving Bootstrapper in a Console App'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-6073757848307873716</id><published>2011-08-31T20:59:00.002+02:00</published><updated>2011-08-31T21:08:26.795+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OWIN'/><category scheme='http://www.blogger.com/atom/ns#' term='Kayak'/><title type='text'>“Hello World” with OWIN (on Kayak)</title><content type='html'>A link to all code can be found at &lt;a href="#gist-1184386"&gt;the end of this post&lt;/a&gt;.

&lt;p&gt;When I started implementing an &lt;a href="http://owin.org/"&gt;OWIN&lt;/a&gt; compatible web framework I couldn’t find any examples on how to get started with OWIN. &lt;a href="http://jclaes.blogspot.com/2011/01/hello-world-with-kayak-and-owin.html"&gt;Jef Claes&lt;/a&gt; has an example but this seems to be for an older draft of OWIN. So this post is about how to create a really simple OWIN web application in C#. It’s inspired by &lt;a href="http://jclaes.blogspot.com/2011/01/hello-world-with-kayak-and-owin.html"&gt;Jef Claes&lt;/a&gt; code and uses code from &lt;a href="http://bvanderveen.com/a/gate-0.1.0/"&gt;Benjamin van der Veen´s example&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Please Note!   
This post was written when OWIN was Draft 1.0, using Kayak 0.7.2 and Gate 0.1.4. Things might have changed since this post.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h2&gt;Set up the project&lt;/h2&gt;  &lt;p&gt;Start by creating a C# Console App.&lt;/p&gt;  &lt;p&gt;Install the &lt;a href="http://nuget.codeplex.com/wikipage?title=Getting%20Started"&gt;NuGet&lt;/a&gt; package &lt;a href="http://nuget.org/list/packages/gate.kayak"&gt;Gate.Kayak&lt;/a&gt;. This will install the these packages too: &lt;a href="http://nuget.org/List/Packages/Gate"&gt;Gate&lt;/a&gt; &amp;amp;  &lt;a href="http://nuget.org/list/packages/kayak"&gt;Kayak&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://kayakhttp.com/"&gt;Kayak&lt;/a&gt; is is an asynchronous HTTP server written in C#.    
&lt;a href="http://nuget.org/list/packages/gate.kayak"&gt;Gate.Kayak&lt;/a&gt; brings OWIN support to Kayak. If you want to host your OWIN app in another environment use another gate like &lt;a href="http://nuget.org/List/Packages/Gate.AspNet"&gt;Gate.AspNet&lt;/a&gt; or &lt;a href="http://nuget.org/List/Packages/Gate.Wcf"&gt;Gate.Wcf&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Create the Kayak Web Server&lt;/h2&gt;  &lt;p&gt;In order to set up a Kayak web server, we need to tell Kayak three things: What endpoint to listen to; how to handle exceptions and shut downs; and how to handle the incoming requests.&lt;/p&gt;  &lt;h3&gt;Main() – Configuring and Starting the Server&lt;/h3&gt;  &lt;p&gt;In this example the &lt;code&gt;Main&lt;/code&gt; method of the Console App configures the Kayak server and starts it.&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)
{
   &lt;span class="rem"&gt;//Create the endpoint for incoming requests to Kayak    &lt;/span&gt;
   var kayakEndPoint = &lt;span class="kwrd"&gt;new&lt;/span&gt; IPEndPoint(IPAddress.Any, 5500);
   Console.WriteLine(&lt;span class="str"&gt;"Listening on "&lt;/span&gt; + kayakEndPoint);

   &lt;span class="rem"&gt;//Start Kayak and call the method Startup.Configuration when starting
&lt;/span&gt;&lt;span class="rem"&gt;    //Let SchedulerDelegate handle exceptions and shut downs&lt;/span&gt;
   KayakGate.Start(&lt;span class="kwrd"&gt;new&lt;/span&gt; SchedulerDelegate(), kayakEndPoint, Startup.Configuration);
}&lt;/pre&gt;

&lt;p&gt;An endpoint on port 5500 is created. When Kayak is starting it will configure itself by calling the &lt;code&gt;Startup.Configuration&lt;/code&gt; method (more on this below), and when stopped, or when an exception is thrown, &lt;code&gt;SchedulerDelegate&lt;/code&gt; handles this.&lt;/p&gt;

&lt;h3&gt;SchedulerDelegate &lt;/h3&gt;

&lt;p&gt;The methods in &lt;code&gt;SchedulerDelegate&lt;/code&gt; class is called when exceptions during Kayak´s event loop occurs and when Kayak is being stopped. We’ll just write messages to the Console.&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; SchedulerDelegate : ISchedulerDelegate
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnException(IScheduler scheduler, Exception e)
   {
       &lt;span class="rem"&gt;// called whenever an exception occurs on Kayak's event loop.&lt;/span&gt;
       &lt;span class="rem"&gt;// this is good place for logging. here's a start:&lt;/span&gt;
       Console.WriteLine(&lt;span class="str"&gt;"Exception on scheduler"&lt;/span&gt;);
       Console.Out.WriteStackTrace(e);
   }

   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnStop(IScheduler scheduler)
   {
       &lt;span class="rem"&gt;// called when Kayak's run loop is about to exit.&lt;/span&gt;
       &lt;span class="rem"&gt;// this is a good place for doing clean-up or other chores.&lt;/span&gt;
       Console.WriteLine(&lt;span class="str"&gt;"Scheduler is stopping."&lt;/span&gt;);
   }
}&lt;/pre&gt;

&lt;h3&gt;Startup.Configuration&lt;/h3&gt;

&lt;p&gt;Next we need to tell Kayak what to do with incoming requests. The method &lt;code&gt;Startup.Configuration&lt;/code&gt; is responsible for that and it will be called when Kayak is starting. In this example, we specified it explicitly in the &lt;code&gt;Main&lt;/code&gt; method, but if you were to host the OWIN application on Asp.Net using &lt;a href="http://nuget.org/List/Packages/Gate.AspNet"&gt;Gate.AspNet&lt;/a&gt; this method will automatically be found and invoked (it’s a convention in Kayak). So creating class with the name &lt;code&gt;Startup&lt;/code&gt; with a static method &lt;code&gt;Configuration&lt;/code&gt; makes your application more easily portable to other Gate hosts.&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; Startup
{
   &lt;span class="rem"&gt;// called automatically when Kayak starts up.&lt;/span&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; Configuration(IAppBuilder builder)
   {
       &lt;span class="rem"&gt;// we'll create a very simple pipeline:&lt;/span&gt;
       var app = &lt;span class="kwrd"&gt;new&lt;/span&gt; HelloWorldOwinApp();
       builder.Run(Delegates.ToDelegate(app.ProcessRequest));
   }
}&lt;/pre&gt;

&lt;p&gt;First our OWIN application is instantiated and then Kayak is told to to let the app´s &lt;code&gt;ProcessRequest&lt;/code&gt; method handle all incoming requests.&lt;/p&gt;

&lt;h2&gt;HelloWorldOwinApp&lt;/h2&gt;

&lt;p&gt;The primary interface in OWIN is the application delegate. An application delegate takes three parameters: an environment dictionary, a response callback, and an error callback. The &lt;code&gt;HelloWorldOwinApp&lt;/code&gt; class exposes the method &lt;code&gt;ProcessRequest&lt;/code&gt; that has the same signature as the application delegate specified in &lt;a href="http://owin.org/spec.html#ApplicationDelegate"&gt;OWIN Draft 1.0&lt;/a&gt; and this is where all the fun happens. &lt;/p&gt;

&lt;p&gt;If the requested resource, i.e. the path, is the root, “/”, we return a Hello World html page. Otherwise a 404 page is returned.&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; HelloWorldOwinApp
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ProcessRequest(
        IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; environment,
       Action&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;,
               Func&amp;lt;Func&amp;lt;ArraySegment&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt;, Action, &lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt;,
               Action&amp;lt;Exception&amp;gt;, Action, Action&amp;gt;&amp;gt; responseCallBack,
       Action&amp;lt;Exception&amp;gt; errorCallback)
   {
       var path = environment[&lt;span class="str"&gt;"owin.RequestPath"&lt;/span&gt;] &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;;
       var responseHeaders = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();
       ArraySegment&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt; responseBody;
       &lt;span class="kwrd"&gt;string&lt;/span&gt; responseStatus;
       &lt;span class="kwrd"&gt;if&lt;/span&gt; (path == &lt;span class="str"&gt;"/"&lt;/span&gt;)
       {
           responseStatus = &lt;span class="str"&gt;"200 OK"&lt;/span&gt;;
           responseHeaders.Add(&lt;span class="str"&gt;"Content-Type"&lt;/span&gt;, &lt;span class="str"&gt;"text/html"&lt;/span&gt;);
           responseBody = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArraySegment&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt;(Encoding.UTF8.GetBytes((
                   &lt;span class="str"&gt;"&amp;lt;!doctype html&amp;gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;meta charset=\"utf-8\"&amp;gt;"&lt;/span&gt; +
                       &lt;span class="str"&gt;"&amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;"&lt;/span&gt; +
                   &lt;span class="str"&gt;"&amp;lt;body&amp;gt;&amp;lt;strong&amp;gt;Hello world&amp;lt;/strong&amp;gt;&amp;lt;/body&amp;gt;"&lt;/span&gt; +
                   &lt;span class="str"&gt;"&amp;lt;/html&amp;gt;"&lt;/span&gt;)));
       }
       &lt;span class="kwrd"&gt;else&lt;/span&gt;
       {
           responseStatus = &lt;span class="str"&gt;"404 Not Found"&lt;/span&gt;;
           responseHeaders.Add(&lt;span class="str"&gt;"Content-Type"&lt;/span&gt;, &lt;span class="str"&gt;"text/html"&lt;/span&gt;);
           responseBody = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArraySegment&amp;lt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;&amp;gt;(Encoding.UTF8.GetBytes((
                   &lt;span class="str"&gt;"&amp;lt;!doctype html&amp;gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;meta charset=\"utf-8\"&amp;gt;"&lt;/span&gt; +
                       &lt;span class="str"&gt;"&amp;lt;title&amp;gt;404 Not Found&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;"&lt;/span&gt; +
                   &lt;span class="str"&gt;"&amp;lt;body&amp;gt;The resource cannot be found.&amp;lt;/body&amp;gt;"&lt;/span&gt; +
                   &lt;span class="str"&gt;"&amp;lt;/html&amp;gt;"&lt;/span&gt;)));
       }
       responseCallBack(
           responseStatus,
           responseHeaders,
           (next, error, complete) =&amp;gt;   // This is the Body Delegate
           {
               next(responseBody, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
               complete();
               &lt;span class="kwrd"&gt;return&lt;/span&gt; () =&amp;gt; { };
           });
   }
}&lt;/pre&gt;

&lt;p&gt;The signature is hideous. The people behind OWIN are well aware of this, and considered interfaces in an assembly that all had to implement, but, thankfully, decided to go with using Funcs and Actions instead. This means that there is no OWIN.dll you have to reference, and therefor no versioning conflicts can occur.&lt;/p&gt;

&lt;p&gt;Except from the signature, this method is pretty straightforward. We get the relative path from the environment dictionary. If it’s “/” we return a Hello World html page. Otherwise a 404 page is returned.&lt;/p&gt;

&lt;p&gt;Returning the resource is a bit special. Instead of just returning some kind of object with headers, status and body content the &lt;code&gt;responseCallBack&lt;/code&gt; is invoked. This is necessary for everything to be asynchronous. The callback has as three arguments: the response status; response headers; and a delegate (the next-error-complete-delegate) for retrieving the body content. &lt;/p&gt;

&lt;p&gt;The delegate is called the Body Delegate and it is invoked by the host whenever it is ready to receive the body content. The signature of the delegate makes it possible to return chunks of the body. But to keep it simple we will return everything in one chunk, and that is what the &lt;code&gt;next(responseBody, null)&lt;/code&gt; call does. &lt;code&gt;responseBody&lt;/code&gt; is an ArraySegment (basically a byte array with information about which part of the array the consumer should use).&lt;/p&gt;

&lt;p&gt;For simple applications, like this, you don’t have to understand how the Body delegate is intended to be used. Just copy-paste this example, and add the content to &lt;code&gt;responseBody&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Say Hello!&lt;/h2&gt;

&lt;p&gt;Start the console app. In a browser navigate to &lt;a href="http://localhost:5500/"&gt;http://localhost:5500&lt;/a&gt;. You should see a page with “Hello World” in bold. Now go to &lt;a href="http://localhost:5500/NotThere"&gt;http://localhost:5500/NotThere&lt;/a&gt; and you’ll get a 404 page.&lt;/p&gt;

&lt;p&gt;That’s it. Now you have everything you need to create a OWIN web application.&lt;/p&gt;

&lt;h2&gt;Code&lt;/h2&gt;

&lt;p id="gist-1184386"&gt;The code can be found on github gist. &lt;a href="https://gist.github.com/1184386"&gt;Show all code&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/4681772286990545567-6073757848307873716?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/6073757848307873716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=6073757848307873716' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/6073757848307873716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/6073757848307873716'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2011/08/hello-world-with-owin-on-kayak.html' title='“Hello World” with OWIN (on Kayak)'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-5952708148632439802</id><published>2011-03-09T15:42:00.001+01:00</published><updated>2011-03-09T15:42:00.190+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='FakeItEasy'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>An extension method for creating a strict mock in FakeItEasy</title><content type='html'>&lt;p&gt;The &lt;a href="http://code.google.com/p/fakeiteasy/"&gt;FakeItEasy&lt;/a&gt; framework prefers that you don’t create strict mocks, but whenever you need one this extension method might come in handy.&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span class="rem"&gt;Creates a strict mock of type &amp;lt;typeparamref name=&amp;quot;T&amp;quot;/&amp;gt;.&lt;/span&gt;&lt;span class="rem"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;typeparam name=&amp;quot;T&amp;quot;&amp;gt;The type of the object to fake.&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;A FakeItEasy fake configured to behave as a strict mock.&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; T Mock&amp;lt;T&amp;gt;()
{
  var fake = A.Fake&amp;lt;T&amp;gt;();
  Any.CallTo(fake).Throws(&lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;An unexpected method was called on the fake object {0}.&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T))));
  &lt;span class="kwrd"&gt;return&lt;/span&gt; fake;
}&lt;/pre&gt;

&lt;p&gt;To create a strict mock:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var foo = AStrict.Mock&amp;lt;IFoo&amp;gt;();&lt;/pre&gt;

&lt;p&gt;After you have configured your mock in this fashion you can configure any &amp;quot;allowed&amp;quot; calls as usual, for example:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;A.CallTo(() =&amp;gt; foo.Bar()).Returns(&lt;span class="str"&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Example and code based on: &lt;a href="http://code.google.com/p/fakeiteasy/wiki/StrictMocks"&gt;http://code.google.com/p/fakeiteasy/wiki/StrictMocks&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/4681772286990545567-5952708148632439802?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/5952708148632439802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=5952708148632439802' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/5952708148632439802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/5952708148632439802'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2011/03/extension-method-for-creating-strict.html' title='An extension method for creating a strict mock in FakeItEasy'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-822942186208289483</id><published>2011-02-13T21:57:00.001+01:00</published><updated>2011-02-13T21:57:15.836+01:00</updated><title type='text'>Set Custom Tool in the Item Template file</title><content type='html'>&lt;p&gt;Documentation for setting the Custom Tool property for a project item created from an item template is not exactly easily found. &lt;/p&gt;  &lt;p&gt;There are two things you need in the .vstemplate-file (I’ll assume you know how to &lt;a title="How to: Create Item Templates in VS 2010 on MSDN" href="http://msdn.microsoft.com/en-us/library/tsyyf0yh.aspx"&gt;create item templates&lt;/a&gt;). First you need to include a WizardExtension-node and next you need to specify a CustomTool attribute on the ProjectItem. Both are marked in yellow below.&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type="text/css"&gt;














.csharpcode .important { background-color: #ff9; }&lt;/style&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;VSTemplate&lt;/span&gt; &lt;span class="attr"&gt;Version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;3.0.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/developer/vstemplate/2005&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Item&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;TemplateData&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;DefaultName&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;MyFile.txt&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DefaultName&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;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;My File&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&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;Description&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;My File&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Description&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;ProjectType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;CSharp&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ProjectType&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;SortOrder&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;SortOrder&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;Icon&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;__TemplateIcon.ico&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Icon&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;TemplateData&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;div class="important"&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;WizardExtension&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;Assembly&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Microsoft.VSDesigner, Version=10.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Assembly&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;FullClassName&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Microsoft.VSDesigner.ProjectWizard.ItemPropertyWizard&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;FullClassName&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;WizardExtension&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TemplateContent&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;References&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;ProjectItem&lt;/span&gt; &lt;span class="attr"&gt;SubType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Code&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;TargetFileName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$fileinputname$.txt&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ReplaceParameters&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="important"&gt;&lt;span class="attr"&gt;CustomTool&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MyCustomTool&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;MyFile.txt&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ProjectItem&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;TemplateContent&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;VSTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-822942186208289483?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/822942186208289483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=822942186208289483' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/822942186208289483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/822942186208289483'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2011/02/set-custom-tool-in-item-template-file.html' title='Set Custom Tool in the Item Template file'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-2795305261819535588</id><published>2010-12-30T15:34:00.001+01:00</published><updated>2010-12-30T15:34:52.629+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WP7'/><title type='text'>How to register for a WP7Dev account</title><content type='html'>&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a6e2c67d-260c-44ca-b570-4d70f8f157b9" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Windows+Phone+7" rel="tag"&gt;Windows Phone 7&lt;/a&gt;,&lt;a href="http://technorati.com/tags/WP7" rel="tag"&gt;WP7&lt;/a&gt;,&lt;a href="http://technorati.com/tags/%23WP7" rel="tag"&gt;#WP7&lt;/a&gt;,&lt;a href="http://technorati.com/tags/%23WP7Dev" rel="tag"&gt;#WP7Dev&lt;/a&gt;&lt;/div&gt;  &lt;p&gt;Want to create applications for the Windows Phone 7 (WP7)? You need to register in order to be able to do that, even if you you only want to deploy the application to your own phone and not to the AppHub. Since I haven’t seen any description of the process I wrote down what I had to to. Note that I live in Sweden and the process might vary by countries, but most likely this is what you have to go thru as an individual non-US developer.&lt;/p&gt;  &lt;h2&gt;1. Register and pay&lt;/h2&gt;  &lt;p&gt;Register at &lt;a title="http://windowsphone.create.msdn.com/AppSubmission" href="http://windowsphone.create.msdn.com/AppSubmission"&gt;http://windowsphone.create.msdn.com/AppSubmission&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Make sure: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;you enter the correct information since it might be hard to change it later: &lt;a href="http://forums.create.msdn.com/forums/t/69335.aspx"&gt;http://forums.create.msdn.com/forums/t/69335.aspx&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;you enter the display name you want since it cannot be changed. At all. Ever: &lt;a href="http://forums.create.msdn.com/forums/t/68212.aspx"&gt;http://forums.create.msdn.com/forums/t/68212.aspx&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Beware that the fee is said to be $99 USD but in reality this might differ, especially if you´re outside US. In Sweden it will cost you €99. Also beware that the amount you’re accepting, which for me was 919 SEK (€99) is not the amount you’ll be charged. To that a tax of 15% is added, so I was charged 1057 SEK ($150). I’m not sure if it’s legal to ask for acceptance of one amount and then charge another. But, according to Shaun Taulbee, Microsoft: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;“Price adjustments are coming, and I'm told refunds will be automatically applied for those who registered since October”        &lt;br /&gt;&lt;/em&gt;&lt;a href="http://forums.create.msdn.com/forums/p/67701/423198.aspx#423198"&gt;http://forums.create.msdn.com/forums/p/67701/423198.aspx#423198&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;2. Email: Confirm the email address! /Microsoft&lt;/h2&gt;  &lt;p&gt;After registering and paying an email will be sent to the email you provided during registration (which might differ from the Live account) in order to confirm the email address. It contains a link that needs to be opened. &lt;/p&gt;  &lt;h2&gt;3. Email: Approve request! /GeoTrust&lt;/h2&gt;  &lt;p&gt;Now you should receive an email form GeoTrust. If you haven’t received it within 24 hrs (remember to check your Spam/Junk email folder first) you should contact GeoTrust directly, according to the FAQ: &lt;a href="http://create.msdn.com/en-US/home/faq/windows_phone_7#wp7faq10"&gt;http://create.msdn.com/en-US/home/faq/windows_phone_7#wp7faq10&lt;/a&gt;     &lt;br /&gt;For me the email came instantly. &lt;/p&gt;  &lt;p&gt;Open the link to GeoTrust that was sent to you in the email an approve the order.    &lt;br /&gt;”Your order has been successfully approved and your authenticated identity validation status will be reflected on the Windows Phone 7 AppHub within two business days.” &lt;/p&gt;  &lt;h2&gt;4. Email: Send identification confirmation! /GeoTrust&lt;/h2&gt;  &lt;p&gt;You just have to wait for the next email from GeoTrust:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;“In order for GeoTrust to confirm your information in terms of Microsoft's requirements, GeoTrust must receive a copy of your valid government issued photo identification (for example: a passport or driver's license), attached to the Identification Confirmation Letter below.”&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You can fax them the information or send it by email, which is what I did: Print out a copy of the letter. Fill the fields at the bottom (all the info is on your passport). Sign it. Scan the letter with your passport at the designated position. Email GeoTrust with the scanned letter as an attachment.&lt;/p&gt;  &lt;h2&gt;5. Email: Your email was received. /GeoTrust&lt;/h2&gt;  &lt;p&gt;After a while you’ll receive an email acknowledging the receipt of your Identification Confirmation email.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;“The verification process will be completed within 1-2 business days. If you have any questions, please contact us.”&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h2&gt;6. “Welcome to the Windows Phone Marketplace developer program”&lt;/h2&gt;  &lt;p&gt;The next email should be from Microsoft welcoming you to the program. For me, it took 6 hours to receive this email.&lt;/p&gt;  &lt;p&gt;You’re done…. Sort of…. In order to receive payment for your apps you’ll need to do more, but I’ll stop here.&lt;/p&gt;  &lt;h2&gt;Shortcutting the process &lt;/h2&gt;  &lt;p&gt;“Wow, that’s many steps and a whole lot of waiting”, you may think. Yeah, it is. But there is a way to speed up the process which worked for me and a &lt;a title="Anders Ljusberg" href="http://coding-insomnia.com/"&gt;friend of mine&lt;/a&gt;. Step 1-3 runs smoothly (no human interaction I would guess), but instead of waiting up to 2 days for step 4 and 5 you can contact GeoTrust via their chat: &lt;a href="https://www.geotrust.com/support/chat/order-processing.html"&gt;https://www.geotrust.com/support/chat/order-processing.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Instead of waiting for step 4, ask them for status of your order.    &lt;br /&gt;After sending the email in step 4, ask them to check they have received the email, and that it contains the correct information.&lt;/p&gt;  &lt;p&gt;For me the steps 1-6 took 2.5 days.&lt;/p&gt;  &lt;h2&gt;Register the phone&lt;/h2&gt;  &lt;p&gt;Connect the phone to your computer. Make sure Zune starts. Start the “Windows Phone Developer Registration” program (from the start menu) and enter your Live ID and Password and click Register. Make sure the phone is not locked. For me it took some attempts. I had to restart the phone and then clicking retry a few times.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-2795305261819535588?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/2795305261819535588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=2795305261819535588' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/2795305261819535588'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/2795305261819535588'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2010/12/how-to-register-for-wp7dev-account.html' title='How to register for a WP7Dev account'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-2515385903604669264</id><published>2010-09-02T17:25:00.001+02:00</published><updated>2010-09-02T17:25:04.604+02:00</updated><title type='text'>How to get the Single File Generator sample running</title><content type='html'>&lt;p&gt;I’ve started developing a CustomTool for Visual Studio 2010. Microsoft has released a sample with documentation on how to implement a Custom Tool. The code can be found here:   &lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/SingleFileGenerator"&gt;http://code.msdn.microsoft.com/SingleFileGenerator&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=186904"&gt;Visual Studio 2010 SDK&lt;/a&gt; must be installed.&lt;/p&gt;  &lt;p&gt;The documentation states “Rebuild the class library and start running it”. Didn’t work. Got the error message saying a class library cannot be started. To be able to debug this is what I did:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In &lt;strong&gt;Solution Explorer&lt;/strong&gt;, right click on &lt;strong&gt;Generator Sample&lt;/strong&gt; and select the menu item &lt;strong&gt;Properties&lt;/strong&gt;.&lt;/li&gt;    &lt;li&gt;On the &lt;strong&gt;Debug&lt;/strong&gt; tab, click the &lt;strong&gt;Start external program radio button&lt;/strong&gt;.&lt;/li&gt;    &lt;li&gt;Browse or enter the path to VS 2010, typically:     &lt;br /&gt;&lt;strong&gt;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;As &lt;strong&gt;Command line arguments&lt;/strong&gt;, enter      &lt;br /&gt;&lt;strong&gt;/ranu /rootsuffix Exp&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;As &lt;strong&gt;Working directory&lt;/strong&gt;, specify the folder for VS2010:      &lt;br /&gt;&lt;strong&gt;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;Set a break point in the XmlClassGenerator.GenerateCode method.&lt;/li&gt;    &lt;li&gt;Press F5 to start debugging.&lt;/li&gt;    &lt;li&gt;A new Visual Studio is started.&lt;/li&gt;    &lt;li&gt;Follow the instructions in the &lt;a href="http://code.msdn.microsoft.com/SingleFileGenerator/Release/ProjectReleases.aspx"&gt;documentation&lt;/a&gt; (create a new class library, create an xml file, fill with content, set CustomTool for file) and the break point will be hit.&lt;/li&gt; &lt;/ol&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-2515385903604669264?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/2515385903604669264/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=2515385903604669264' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/2515385903604669264'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/2515385903604669264'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2010/09/how-to-get-single-file-generator-sample.html' title='How to get the Single File Generator sample running'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-7501703004351619160</id><published>2009-12-03T21:45:00.001+01:00</published><updated>2009-12-03T21:47:06.898+01:00</updated><title type='text'>How to remotely connect to ASP.Net Development Server</title><content type='html'>&lt;p&gt;The ASP.Net Development Server (webdev.webserver.exe), which is included with Visual Studio, is used when testing web applications locally when IIS isn’t installed. The ASP.Net Development Server will only serve pages to browser requests on the local computer, so a colleague of yours cannot have a look at what you’re doing, since ASP.Net Development Server will not serve pages to another computer. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_uLEBEDJEESU/Sxgje8oreSI/AAAAAAAAAGs/0C5tWoiPCpo/s1600-h/image%5B2%5D.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/_uLEBEDJEESU/Sxgjfdq9iRI/AAAAAAAAAGw/md7NIDp7fcs/image_thumb.png?imgmax=800" width="244" height="78" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In order to remotely connect to the ASP.Net Development Server a proxy must be used that accepts remote connections and proxies traffic to and from the ASP.Net Development Server.&lt;/p&gt;  &lt;p&gt;I searched the internet for a suitable proxy but I couldn’t find one that is small and easy to use (ok, I admit, I didn’t search &lt;em&gt;that&lt;/em&gt; long :-) so I wrote one based on proxy code from &lt;a title="http://www.mentalis.org/soft/projects/proxy/" href="http://www.mentalis.org/soft/projects/proxy/"&gt;http://www.mentalis.org/soft/projects/proxy/&lt;/a&gt;.&amp;#160; It’s probable not the most elegant piece of code ever written but it will have to do.&lt;/p&gt;  &lt;p&gt;To start the proxy just pass the port number to it:&lt;/p&gt;  &lt;pre&gt;Proxy.exe 62200&lt;/pre&gt;

&lt;p&gt;Incoming traffic to port 80 (standard http port) is proxied to 62200, so if your computer’s name is YourComputer, your colleague can connect on the url: http://YourComputer/&lt;/p&gt;

&lt;p&gt;To listen to another port than 80, specify it as the second argument:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre&gt;Proxy.exe 62200 15555&lt;/pre&gt;

&lt;p&gt;Incoming traffic to port 15555&amp;#160; is proxied to 62200, so the url will be: http://YourComputer:15555/&lt;/p&gt;

&lt;h2&gt;Download&lt;/h2&gt;

&lt;p&gt;Download executable and source here: 
  &lt;br /&gt;&lt;a title="http://cid-1591ce8777facfb4.skydrive.live.com/browse.aspx/Public/Code/Proxy" href="http://cid-1591ce8777facfb4.skydrive.live.com/browse.aspx/Public/Code/Proxy"&gt;http://cid-1591ce8777facfb4.skydrive.live.com/browse.aspx/Public/Code/Proxy&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/4681772286990545567-7501703004351619160?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/7501703004351619160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=7501703004351619160' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/7501703004351619160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/7501703004351619160'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2009/12/how-to-remotely-connect-to-aspnet.html' title='How to remotely connect to ASP.Net Development Server'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_uLEBEDJEESU/Sxgjfdq9iRI/AAAAAAAAAGw/md7NIDp7fcs/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-3954262993222344480</id><published>2008-12-18T17:32:00.001+01:00</published><updated>2008-12-18T17:32:31.618+01:00</updated><title type='text'>How to deploy a VS Database Project GDR using vsdbcmd</title><content type='html'>&lt;p&gt;With the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;amp;displaylang=en"&gt;release of Visual Studio Team System 2008 Database Edition GDR&lt;/a&gt; we now have the possibility to use a standalone command for deploying a database project. Unfortunately the documentation for the new vsdbcmd is so full of errors that you cannot use it, see for example “Command-line Reference for VSDBCMD (Deployment and Schema Import)” and “How to: Prepare a Database for Deployment From a Command Prompt by Using VSDBCMD ”. Seems to be written for a previous version. &lt;/p&gt;  &lt;h2&gt;Properties&lt;/h2&gt;  &lt;p&gt;The documentation states that you should specify properties using this syntax:&lt;/p&gt;  &lt;pre&gt;/p:PropertyName:PropertyValue    INCORRECT!&lt;/pre&gt;

&lt;p&gt;The correct syntax is:&lt;/p&gt;

&lt;pre&gt;/p:PropertyName=PropertyValue &lt;/pre&gt;

&lt;h2&gt;Verbose and quiet&lt;/h2&gt;

&lt;p&gt;It also states that there exists a /verbose or /v option. This option do not exist. It has been removed. It’s verbose by default and you can use the undocumented /quiet or /q to turn of verbosity [&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e188dd40-dfe0-45a0-b75b-fcf7d187c2b9/#f9ee85f4-4ea9-4646-9d6d-75162fa77535"&gt;source&lt;/a&gt;].&lt;/p&gt;

&lt;h2&gt;Invalid property names&lt;/h2&gt;

&lt;p&gt;The common deployment properties list isn’t right either. For example the TargetDatabaseName is in fact called TargetDatabase. Have a look in the .sqldeployment and .deploymanifest files for proper naming. These files exists in the directory created when building the project, for example MyDbProject/sql/debug/.&lt;/p&gt;

&lt;h2&gt;Deploy-example&lt;/h2&gt;

&lt;p&gt;Below is an example of how to deploy a database project that has been built by Visual Studio or Team Server Foundation (TFS). &lt;/p&gt;

&lt;p&gt;Start a command prompt and change directory to the directory that was created when the project was built (for example MyDbProject/sql/debug/) and execute the command below (on a single line).&lt;/p&gt;

&lt;pre&gt;&amp;quot;%ProgramFiles%\Microsoft Visual Studio 9.0\VSTSDB\deploy\vsdbcmd&amp;quot;&lt;br /&gt;  /a:Deploy &lt;br /&gt;  /ConnectionString:&amp;quot;Data Source=&lt;em&gt;MyServer&lt;/em&gt;;Integrated Security=True;&amp;quot; &lt;br /&gt;  /dsp:SQL &lt;br /&gt;  /manifest:&lt;em&gt;MyDbProject&lt;/em&gt;.deploymanifest &lt;br /&gt;  /p:TargetDatabase=&lt;em&gt;MyDb&lt;/em&gt; &lt;br /&gt;  /dd&lt;/pre&gt;

&lt;p&gt;This will create a .sql file and deploy it, i.e. execute it on the server. If you remove the /dd option the .sql will be created but not deployed.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-3954262993222344480?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/3954262993222344480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=3954262993222344480' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/3954262993222344480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/3954262993222344480'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2008/12/how-to-deploy-vs-database-project-gdr.html' title='How to deploy a VS Database Project GDR using vsdbcmd'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-4337066407620983363</id><published>2008-07-27T13:59:00.001+02:00</published><updated>2008-07-27T13:59:19.912+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>How to include scripts after asp.net ajax framework's</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2008/07/inkludera-script-efter-aspnet-ajax.html"&gt;Swedish version of this entry&lt;/a&gt; &lt;/div&gt;  &lt;p&gt;When registering script includes using &lt;a href="http://msdn.microsoft.com/sv-se/library/system.web.ui.scriptmanager.registerclientscriptinclude(en-us).aspx"&gt;ScriptManager.RegisterClientScriptInclude(&amp;quot;myFile.js&amp;quot;)&lt;/a&gt; the files are always included before the frameworks. This causes errors if your code depends on the ajax framework's. Errors like &amp;quot;Type is not defined&amp;quot; are common since the first line in the included script file often tries to register a namespace: Type.registerNamespace('My.Namespace');&lt;/p&gt;  &lt;p&gt;On the other hand, files registered as ScriptReferences on the ScriptManagerProxy will be included AFTER the framework's includes.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ScriptManagerProxy&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;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ScriptManagerProxy1&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;Scripts&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ScriptReference&lt;/span&gt; &lt;span class="attr"&gt;Path&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;~/anotherFile.js&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Scripts&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:ScriptManagerProxy&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Not exactly the expected behavior and certainly not what we want.&lt;/p&gt;

&lt;p&gt;When calling &lt;a href="http://msdn.microsoft.com/sv-se/library/system.web.ui.scriptmanager.registerclientscriptinclude(en-us).aspx"&gt;ScriptManager&lt;/a&gt;.RegisterClientScriptInclude() it delegates to the class ClientScriptManager. This class holds, internally, a list of registered scripts, and new entries ends up at the end. So the call ScriptManager.RegisterClientScriptInclude(&amp;quot;myFile.js&amp;quot;) will put myFile.js at the end of that list. Like this:&lt;/p&gt;

&lt;pre&gt;ClientScriptManagerClientScripts = { ..., &amp;quot;~/myFile.js&amp;quot; }&lt;/pre&gt;

&lt;p&gt;The references in the ScriptManagerProxies are handled a bit differently. The ScriptManager will, on the event PagePreRenderComplete, collect all references from the proxies in a list, and first in that list put the ajax framework's files. &lt;/p&gt;

&lt;pre&gt;List in ScriptManager = { ajax framework files, &amp;quot;~/anotherFile.js&amp;quot; }&lt;/pre&gt;

&lt;p&gt;After being collected the files are registered with the ClientScriptManager and are appended at the end of it's list. Since we registered myFile.js before PagePreRenderComplete (which occurs late in the asp.net page's life cycle), myFile.js is before the framework's files:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre&gt;ClientScriptManagerClientScripts = { ..., &amp;quot;~/myFile.js&amp;quot;, ..., ajax framework files, &amp;quot;~/anotherFile.js&amp;quot;}&lt;/pre&gt;

&lt;p&gt;These are rendered to the page in this order and it explains why anotherFile.js may use the framework directly and myFile.js not.&lt;/p&gt;

&lt;h2&gt;Solution 1. Use a proxy&lt;/h2&gt;

&lt;p&gt;The simplest solution is to put a ScriptManagerProxy on the page (or user control, or MasterPage) and either, as shown above declare a ScriptReference, or add one by code:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;ScriptManagerProxy1.Scripts.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; ScriptReference(&lt;span class="str"&gt;&amp;quot;~/myFile.js&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

&lt;h2&gt;Solution 2. Register the file after PagePreRenderComplete&lt;/h2&gt;

&lt;p&gt;If you somehow manage to register myFile.js after PagePreRenderComplete (i.e. after ScriptControl has added all files) it will end up after the framework's files. But you'll need to do it before the rendering takes place. Between PreRender and Render phases is the SaveViewState phase. If we override SaveViewState on a control (Page is also a control) and registers myFile.js there it will be added to the list after the framework's files. This is sort of a hack and it's not guaranteed to work when new versions of the framework are released, but: It works.&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;object&lt;/span&gt; SaveViewState()
{
    ScriptManager.RegisterClientScriptInclude(&lt;span class="kwrd"&gt;this&lt;/span&gt;,GetType(),&lt;span class="str"&gt;&amp;quot;myFile&amp;quot;&lt;/span&gt;,&lt;span class="str"&gt;&amp;quot;~/myFile.js&amp;quot;&lt;/span&gt;);
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.SaveViewState();
}&lt;/pre&gt;

&lt;h2&gt;Solution 3. Your own ScriptManager&lt;/h2&gt;

&lt;p&gt;This is, at least to me, the most elegant solution. Basically: you create the class MyScriptManager, which derives from ScriptManager; you replace the ScriptManager on the page (or user control, or MasterPage) with MyScriptManager; add the method RegisterClientScriptInclude(string url) to MyScriptManager and by some magic inside MyScriptManager makes sure that files registered thru the new method will be rendered after the ajax framework's includes.&lt;/p&gt;

&lt;p&gt;When the ScriptManager collects all the ScriptReferences from the proxies (as explained above) it also collects ScriptReferences from all controls that have been registered with the ScriptManager as ScriptControls, by calling the method GetScriptReferences, that ScriptControls must implement. These files will be added after the proxies' files.&lt;/p&gt;

&lt;p&gt;This is what we'll do: The new RegisterClientScriptInclude method will only add the url to a list, and not register it anywhere else. We let MyScriptManager be a ScriptControl (i.e. implement IScriptControl) and register itself as such. In the method GetScriptReferences we will, when requested, supply the list of registered files, and they will end up after the framework's.&lt;/p&gt;

&lt;p&gt;Not much code is needed.&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; MyScriptManager : ScriptManager, IScriptControl
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; _registeredScripts = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();

    &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; RegisterClientScriptInclude(&lt;span class="kwrd"&gt;string&lt;/span&gt; url)
    {
        _registeredScripts.Add(url);
    }

    &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; OnPreRender(EventArgs e)
    {
        &lt;span class="rem"&gt;//Register this instance as a ScriptControl.&lt;/span&gt;
        RegisterScriptControl(&lt;span class="kwrd"&gt;this&lt;/span&gt;);
        &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnPreRender(e);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; MyScriptManager GetCurrent(Page page)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (MyScriptManager) ScriptManager.GetCurrent(page);
    }

    &lt;span class="preproc"&gt;#region&lt;/span&gt; IScriptControl Members
    IEnumerable&amp;lt;ScriptDescriptor&amp;gt; IScriptControl.GetScriptDescriptors()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }

    IEnumerable&amp;lt;ScriptReference&amp;gt; IScriptControl.GetScriptReferences()
    {
        &lt;span class="rem"&gt;//For each element in _registeredScripts create a
        //ScriptReference and return the IEnumerable&lt;/span&gt;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; _registeredScripts.ConvertAll(s =&amp;gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ScriptReference(s));
    }
    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
}&lt;/pre&gt;

&lt;p&gt;Please note that I've simplified the code in order to show the concept. In production code you'll want to encapsulate the list in a public property that creates the list if needed. And you want two protected virtual versions of GetScriptDescriptors and GetScriptReferences that the existing ones will call. &lt;/p&gt;

&lt;p&gt;To register a file to be included after the framework's files you use:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;MyScriptManager.GetCurrent(Page).RegisterClientScriptInclude(&lt;span class="str"&gt;&amp;quot;~/myFile.js&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;If you're using AjaxControlToolkit change the inheritance to ToolkitScriptManager.&lt;/p&gt;

&lt;p&gt;Note the order the files are included: &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;ScriptManager.RegisterClientScriptInclude registered files &lt;/li&gt;

  &lt;li&gt;Ajax framework's files &lt;/li&gt;

  &lt;li&gt;All ScriptManagerProxy ScriptReferences &lt;/li&gt;

  &lt;li&gt;MyScriptManager.RegisterClientScriptInclude registered files &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you want your files to be included between 2 and three you're in deep water. It's probably doable but far from trivial, since ScriptManager is pretty closed for extension. It would be nice if Microsoft adhered the &lt;a href="http://en.wikipedia.org/wiki/Open/closed_principle"&gt;Open/Closed-principle&lt;/a&gt; a bit more. :)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-4337066407620983363?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/4337066407620983363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=4337066407620983363' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/4337066407620983363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/4337066407620983363'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2008/07/how-to-include-scripts-after-aspnet.html' title='How to include scripts after asp.net ajax framework&amp;#39;s'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-1465618402178443444</id><published>2007-07-27T17:33:00.001+02:00</published><updated>2007-07-27T17:35:05.936+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><title type='text'>AutoEventWireup=true</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/07/autoeventwireuptrue.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt; &lt;p&gt;If you specify the attribute&amp;nbsp;&lt;em&gt;AutoEventWireup=True&lt;/em&gt; on a Web User Control or a Page, methods like &lt;em&gt;Page_Init() &lt;/em&gt;och &lt;em&gt;Page_Load() &lt;/em&gt;will be automatically routed to the page's &lt;em&gt;Init&lt;/em&gt;- and &lt;em&gt;Load&lt;/em&gt;-events.&lt;/p&gt; &lt;p&gt;This is good, sometimes. It simplifies for you since you don't have to hook up events to event handlers.&amp;nbsp;But it is something that's done during runtime, and therefore&amp;nbsp;adds to the executiion time and it may cause event handlers to be called many times.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Example:&amp;nbsp;Event handler beeing called twice.&lt;/strong&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Page_Init()
{
    Page.Load += Page_Load;
}
&lt;span style="color: rgb(0,0,255)"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; e)
{
    &lt;span style="color: rgb(0,128,0)"&gt;//This code will execute twice
&lt;/span&gt;}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;em&gt;Page_Load&lt;/em&gt; in the example above will be called twice. Once since you mannually hooked the event to the &lt;em&gt;Page_Load&lt;/em&gt; handler. Another time since &lt;em&gt;AutoEventWireup=true&lt;/em&gt; and the method has a name causing the event to automatically be hooked to it.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;AutoEventWireup&lt;/em&gt; works on &lt;em&gt;TemplateControl&lt;/em&gt; which both &lt;em&gt;Page&lt;/em&gt; och &lt;em&gt;Web User Controls&lt;/em&gt; derives from. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx"&gt;K Scott Allen's blog&lt;/a&gt; talkes about this. I'll go more into depths.&lt;/p&gt;
&lt;h2&gt;SupportAutoEvents&lt;/h2&gt;
&lt;p&gt;What happens when&amp;nbsp;&lt;em&gt;AutoEventWireup=true?&lt;/em&gt; A &lt;em&gt;TemplateControl&lt;/em&gt; has a property &lt;em&gt;SupportAutoEvents&lt;/em&gt;. This is t&lt;em&gt;rue&lt;/em&gt; by default (and will change to &lt;em&gt;false&lt;/em&gt; by the parser/control builderif you set the attribute &lt;em&gt;AutoEventWireup=false&lt;/em&gt;).&lt;/p&gt;
&lt;h2&gt;HookUpAutomaticHandlers &lt;/h2&gt;
&lt;p&gt;&lt;em&gt;TemplateControl.HookUpAutomaticHandlers&lt;/em&gt; (which is called during the &lt;em&gt;OnInit&lt;/em&gt;)&amp;nbsp;will, if&amp;nbsp;&lt;em&gt;AutoEventWireup=true&lt;/em&gt; try to find methods with these names:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If the control is a &lt;em&gt;Page&lt;/em&gt;: 
&lt;ul&gt;
&lt;li&gt;Page_PreInit 
&lt;li&gt;Page_PreLoad 
&lt;li&gt;Page_LoadComplete 
&lt;li&gt;Page_PreRenderComplete 
&lt;li&gt;Page_InitComplete 
&lt;li&gt;Page_SaveStateComplete &lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;For all &lt;em&gt;TemplateControls&lt;/em&gt;: 
&lt;ul&gt;
&lt;li&gt;Page_Init 
&lt;li&gt;Page_Load 
&lt;li&gt;Page_DataBind 
&lt;li&gt;Page_PreRender 
&lt;li&gt;Page_Unload 
&lt;li&gt;Page_Error 
&lt;li&gt;Page_AbortTransaction &amp;nbsp;or if it does not exist;&amp;nbsp;OnTransactionAbort 
&lt;li&gt;Page_CommitTransaction&amp;nbsp; or if it does not exist; OnTransactionCommit&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;This is carried out in&amp;nbsp;&lt;em&gt;TemplateControl.GetDelegateInformationWithNoAssert()&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;32 attempts&lt;/h3&gt;
&lt;p&gt;As &lt;a href="http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx"&gt;K Scott Allen&lt;/a&gt; writes two attempts will be made for every name. First it will try to find an &lt;em&gt;EventHandler&lt;/em&gt; with the specified name, i.e. a method with the signature:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; EventHandler(&lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; e)&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;strong&gt;Exemple: A method that is an EventHandler&lt;/strong&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Page_PreInit(&lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; e)&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;If that fails a VoidMethod is searched for, i.e. a method with the signature:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; VoidMethod()&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Exemple: A method that is a&lt;/strong&gt; VoidMethod&lt;/strong&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Page_PreInit()&lt;/pre&gt;
&lt;p&gt;Although no methods&amp;nbsp;matching the list have been added to the Page, 32 attempts to find a method will be made (K Scott Allen got 28 but he must have forgotten about OnTransactionAbort and OnTransactionCount).&lt;/p&gt;
&lt;p&gt;Ok, the result will be cached but the search will be made at least once, at that's for every TemplateControl. &lt;/p&gt;
&lt;h3&gt;Hook up the event to the handler&lt;/h3&gt;
&lt;p&gt;For all matching methods on the control &lt;em&gt;TemplateControl.HookUpAutomaticHandlers()&lt;/em&gt;&amp;nbsp;will hook up&amp;nbsp;the event to the corresponding event handler, unless the method already has been added to the event since &lt;em&gt;HookUpAutomaticHandlers&lt;/em&gt;&amp;nbsp;searches the list of event handlers for the event. If it finds the method, it will not add the method again.&lt;/p&gt;
&lt;p&gt;But wait. In the first example &lt;em&gt;Page_Load()&lt;/em&gt; was obviously added twice to the event. &lt;br&gt;Yes, but that's because &lt;em&gt;HookUpAutomaticHandlers&lt;/em&gt; already had hooked up the &lt;em&gt;Page.Load&lt;/em&gt; event to the &lt;em&gt;Page_Load&lt;/em&gt; handler&amp;nbsp;when we in &lt;em&gt;Page_Init &lt;/em&gt;did it. Remember that&amp;nbsp;&lt;em&gt;HookUpAutomaticHandlers&lt;/em&gt;&amp;nbsp;is called in the Page's&amp;nbsp;&lt;em&gt;OnInit&lt;/em&gt;, which is called before our &lt;em&gt;Page_Init&lt;/em&gt;&amp;nbsp;method.&amp;nbsp;If we hook up the event to the handler &lt;strong&gt;before&lt;/strong&gt; the page's&amp;nbsp;&lt;em&gt;OnInit&lt;/em&gt; we will do it before the &lt;em&gt;HookUpAutomaticHandlers&lt;/em&gt; has ben called and therefore &lt;em&gt;Page_Load&lt;/em&gt; will only be called once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Exemple: Page_Load is only called once.&lt;/strong&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;partial&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;_Default&lt;/span&gt; : System.Web.UI.&lt;span style="color: rgb(43,145,175)"&gt;Page
&lt;/span&gt;{
    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; _Default()
    {
        Page.Load += Page_Load;
    }

    &lt;span style="color: rgb(0,0,255)"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43,145,175)"&gt;EventArgs&lt;/span&gt; e)
    {
        &lt;span style="color: rgb(0,128,0)"&gt;//This code will execute once
&lt;/span&gt;    }
}&lt;/pre&gt;
&lt;h2&gt;Conclusion: AutoEventWireup=false&lt;/h2&gt;
&lt;p&gt;Consider setting &lt;em&gt;AutoEventWireup=false&lt;/em&gt; and manually hook up the events to the handlers. You gain control over when things are called and you don't have to pay for the overhead &lt;em&gt;TemplateControl.HookUpAutomaticHandlers&lt;/em&gt;&amp;nbsp;causes. &lt;/p&gt;
&lt;p&gt;Microsoft recommends setting it to &lt;em&gt;false&lt;/em&gt; if performance is a key consideration.&lt;/p&gt;
&lt;h2&gt;More on&amp;nbsp;AutoEventWireup on MSDN&lt;/h2&gt;
&lt;p&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup.aspx" href="http://msdn2.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup.aspx"&gt;http://msdn2.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup.aspx&lt;/a&gt;&lt;br&gt;&lt;a title="http://support.microsoft.com/default.aspx/kb/324151" href="http://support.microsoft.com/default.aspx/kb/324151"&gt;http://support.microsoft.com/default.aspx/kb/324151&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/4681772286990545567-1465618402178443444?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/1465618402178443444/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=1465618402178443444' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/1465618402178443444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/1465618402178443444'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/07/autoeventwireuptrue.html' title='AutoEventWireup=true'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-7548692939669303147</id><published>2007-05-21T15:09:00.000+02:00</published><updated>2007-05-21T15:42:32.051+02:00</updated><title type='text'>Insert Do-nothing comments</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/05/infoga-do-nothing-kommentarer.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;Always insert a &lt;code&gt;//Do nothing&lt;/code&gt; comment in places where the intention is that nothing should be done.

Let Me show you why by an example. Assume you have a constructor for a Control that inherits WebControl and all you want to do is changing the default tag (which is Span).&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; MyControl()
   :&lt;span class="kwrd"&gt;base&lt;/span&gt;(HtmlTextWriterTag.Div)
{
}&lt;/pre&gt;When someone else reads this code (or you in a month or so when you've forgotten all about it) they might wonder if this code has been finished or if there is something  missing in the constructor. By adding a comment, you show for anyone reading the code that there shouldn't really be any code inside the constructor.&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; MyControl()
   :&lt;span class="kwrd"&gt;base&lt;/span&gt;(HtmlTextWriterTag.Div)
{
   &lt;span class="highlight rem"&gt;//Do nothing&lt;/span&gt;
}&lt;/pre&gt;
I have a code snippet for this so I just need to type &lt;code&gt;don&lt;/code&gt; and hit tab twice and &lt;code&gt;//Do nothing&lt;/code&gt; is inserted.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-7548692939669303147?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/7548692939669303147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=7548692939669303147' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/7548692939669303147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/7548692939669303147'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/05/insert-do-nothing-comments.html' title='Insert Do-nothing comments'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-8616954397353457772</id><published>2007-05-18T10:23:00.000+02:00</published><updated>2007-05-20T00:57:06.034+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><title type='text'>Passing values to behavior properties</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/05/english-version-of-this-entry-en.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;Typically a property in a AjaxControlToolkit Extender looks like this:
&lt;pre&gt;[ExtenderControlProperty]
[DefaultValue("")]
public string MyProperty
{
  get { ... }
  set { ... }
}&lt;/pre&gt;Which will match a property in the behavior:&lt;pre&gt;get_MyProperty : function() { ... },
set_MyProperty : function(value) { ... }&lt;/pre&gt;
Values for &lt;code&gt;MyProperty&lt;/code&gt; on the server side will end up in the behavior.

Sometimes you want to pass values to the behavior without creating a property in the Extender control. To do this, simply override &lt;code&gt;RenderScriptAttributes()&lt;/code&gt; and add the properties using &lt;code&gt;AddProperty()&lt;/code&gt;.&lt;pre&gt;protected override void RenderScriptAttributes(ScriptBehaviorDescriptor descriptor)
{
  base.RenderScriptAttributes(descriptor);
  string horizontalAlignment=GetHorizontalAlignment();
  descriptor.AddProperty("HorizontalAlignment", horizontalAlignment);
}&lt;/pre&gt;
And voilà, the &lt;b&gt;HorizontalAlignment&lt;/b&gt; property in the beahvior will be set.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-8616954397353457772?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/8616954397353457772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=8616954397353457772' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/8616954397353457772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/8616954397353457772'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/05/adding-extender-properties.html' title='Passing values to behavior properties'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-8431596529775325969</id><published>2007-05-18T09:39:00.000+02:00</published><updated>2007-05-20T00:46:55.804+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='Extenders'/><title type='text'>Property names &amp; Extenders</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/05/namn-p-properties-i-ajax-extenders.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;Properties for extenders inheriting &lt;code&gt;ExtenderControlBase&lt;/code&gt; typically looks like this:
&lt;pre&gt;[ExtenderControlProperty]
[DefaultValue("")]
public string MyProperty
{
  get
  {
    return GetPropertyValue("MyProperty", "");
  }
  set
  {
    SetPropertyValue("MyProperty", value);
  }
}&lt;/pre&gt; 

You must have a property with the same name in the behavior on the client side:
&lt;pre&gt;get_MyProperty : function() {
  return this._myProperty;
},
set_MyProperty : function(value) {
  this._myProperty = value;
}&lt;/pre&gt;

But what if you want it to have different name on the client side? Easy. Add the &lt;code&gt;ClientPropertyName&lt;/code&gt; attribute to the server side property. If we want &lt;code&gt;MyProperty&lt;/code&gt; to be called &lt;b&gt;myProp&lt;/b&gt; instead this is how it's done:
&lt;pre&gt;[ExtenderControlProperty]
[DefaultValue("")]
&lt;span class="highlight"&gt;[ClientPropertyName("myProp")]&lt;/span&gt;
public string MyProperty
{
  get
  {
    return GetPropertyValue("MyProperty", "");
  }
  set
  {
    SetPropertyValue("MyProperty", value);
  }
}&lt;/pre&gt; 

On the client side we get:
&lt;pre&gt;get_&lt;span class="highlight"&gt;myProp&lt;/span&gt; : function() {
  return this._myProperty;
},
set_&lt;span class="highlight"&gt;myProp&lt;/span&gt; : function(value) {
  this._myProperty = value;
}&lt;/pre&gt;

More on attributes:
&lt;a href="http://ajax.asp.net/ajaxtoolkit/Walkthrough/ExtenderClasses.aspx"&gt;http://ajax.asp.net/ajaxtoolkit/Walkthrough/ExtenderClasses.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-8431596529775325969?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/8431596529775325969/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=8431596529775325969' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/8431596529775325969'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/8431596529775325969'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/05/setting-property-names.html' title='Property names &amp; Extenders'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-2972866976273265024</id><published>2007-05-10T12:28:00.000+02:00</published><updated>2007-05-20T00:30:10.914+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><title type='text'>OOP in Javascript</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/05/english-version-of-this-entry-msdn.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;MSDN Magazine May 2007 edition has an interesting article on how to use object oriented  techniques in Javascript. A must-read if you are using Microsoft AJAX since the entire client script library is written using these techniques.

&lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/05/JavaScript/default.aspx"&gt;http://msdn.microsoft.com/msdnmag/issues/07/05/JavaScript/default.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-2972866976273265024?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/2972866976273265024/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=2972866976273265024' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/2972866976273265024'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/2972866976273265024'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/05/oop-in-javascript.html' title='OOP in Javascript'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-8267661889802749074</id><published>2007-03-22T16:16:00.000+01:00</published><updated>2007-05-20T00:23:53.688+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><title type='text'>Validators not working with UpdatePanel??</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/05/validators-fungerar-inte-med.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;The validators don't work very well sometimes when put in an UpdatePanel. But they used to...

The reason is that in the 1.0 release of Ajax asp.net the validators that were used in place of the the ordinary asp.net validators have been removed. There was supposed to be an update available for the System.Web namespace to overcome this problem but it will take some time before we have the update. In the meantime there is a fix available.

Have a look here: &lt;a href="http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx"&gt;http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-8267661889802749074?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/8267661889802749074/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=8267661889802749074' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/8267661889802749074'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/8267661889802749074'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/03/validators-not-working-with-updatepanel.html' title='Validators not working with UpdatePanel??'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-5771457536934227316</id><published>2007-02-16T10:49:00.000+01:00</published><updated>2007-03-22T13:41:05.586+01:00</updated><title type='text'>Shortcuts and Cheat Sheets</title><content type='html'>Keyboard shortcuts for VS 20005:
&lt;a href="http://blogs.msdn.com/robcaron/archive/2007/01/29/1552795.aspx"&gt;http://blogs.msdn.com/robcaron/archive/2007/01/29/1552795.aspx&lt;/a&gt;

Regular Expressions cheat sheet:
&lt;a href="http://www.ilovejackdaniels.com/cheat-sheets/regular-expressions-cheat-sheet/"&gt;http://www.ilovejackdaniels.com/cheat-sheets/regular-expressions-cheat-sheet/&lt;/a&gt;

CSS cheat sheet
&lt;a href="http://www.ilovejackdaniels.com/cheat-sheets/css-cheat-sheet/"&gt;http://www.ilovejackdaniels.com/cheat-sheets/css-cheat-sheet/&lt;/a&gt;

JavaScript cheat sheet
&lt;a href="http://www.ilovejackdaniels.com/cheat-sheets/javascript-cheat-sheet/"&gt;http://www.ilovejackdaniels.com/cheat-sheets/javascript-cheat-sheet/&lt;/a&gt;

Asp.net Lifecycle:
&lt;a href="http://john-sheehan.com/blog/index.php/net-cheat-sheets/"&gt;http://john-sheehan.com/blog/index.php/net-cheat-sheets/&lt;/a&gt;

AJAX asp.net
&lt;a href="http://aspnetresources.com/blog/ms_ajax_cheat_sheets_batch2.aspx"&gt;http://aspnetresources.com/blog/ms_ajax_cheat_sheets_batch2.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-5771457536934227316?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/5771457536934227316/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=5771457536934227316' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/5771457536934227316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/5771457536934227316'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/02/shortcuts-and-cheat-sheets.html' title='Shortcuts and Cheat Sheets'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-4084031233372545709</id><published>2007-02-08T14:45:00.000+01:00</published><updated>2007-05-20T00:15:42.788+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><title type='text'>Don't access the property ClientId to early</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/02/fippla-inte-med-clientid-fr-tidigt.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;The ClientId property on a Control is correct only after the control has been added to a Parent, i.e. added to a Controls collection. The parent must also be connected to a parent, and it's parent, and so on up al the way to the Page control.

If you try to get ClientId to early, not only will you get something unusable, it will be cached so all subsequent calls will get the same. It will also prevent postback events from working.

Big No-no:
&lt;pre&gt;public class MyControl : CompositeControl
{
 protected override void CreateChildControls()
 {
  Button myButton = new Button();
  myButton.Text = "Unclicked";
  myButton.Click += new EventHandler(myButton_Click);
  Controls.Add(myButton);
  
  //MyControl has no parent yet. The following code will prevent
  //the myButton_Click from beeing called when the button is clicked.
  //Remove the line and it will be called.
  &lt;span class="highlight"&gt;string id = myButton.ClientID; &lt;/span&gt;
 }
 
 void myButton_Click(object sender, EventArgs e)
 {
  Button button = (Button)sender;
  button.Text = "clicked";
 }
}
&lt;/pre&gt;

Another example: &lt;a href="http://aspadvice.com/blogs/joteke/archive/2007/01/28/Accessing-ClientID-or-UniqueID-too-early-can-cause-issues.aspx"&gt;http://aspadvice.com/blogs/joteke/archive/2007/01/28/Accessing-ClientID-or-UniqueID-too-early-can-cause-issues.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-4084031233372545709?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/4084031233372545709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=4084031233372545709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/4084031233372545709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/4084031233372545709'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/02/dont-access-property-clientid-to-early.html' title='Don&apos;t access the property ClientId to early'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-8750943578024384099</id><published>2007-01-31T18:08:00.000+01:00</published><updated>2007-05-19T23:59:10.905+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><title type='text'>Find a control in javascript (Ajax ASP.Net)</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/01/hitta-en-kontroll-i-javascript-ajax.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;To find a control with id "MyControl" us the function $get.
Example:&lt;pre&gt;alert(&lt;span class="highlight"&gt;$get("MyControl")&lt;/span&gt;.id);&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-8750943578024384099?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/8750943578024384099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=8750943578024384099' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/8750943578024384099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/8750943578024384099'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/01/find-control-in-javascript-ajax-aspnet.html' title='Find a control in javascript (Ajax ASP.Net)'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-6071327409485301357</id><published>2007-01-31T16:44:00.000+01:00</published><updated>2007-05-19T23:53:50.554+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><title type='text'>Show and Hide a ModalPopupExtender  from javascript</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/05/untitled.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;To show a modal popup handled by a ModalPopupExtender from javascript you need to set the BehaviorID property:
&lt;pre&gt;
&amp;lt;ajaxToolkit:ModalPopupExtender...
BehaviorID="MyModalPopupExtender"
... /&amp;gt; &lt;/pre&gt;

The script for showing and hiding the popup:
&lt;pre&gt;
&amp;lt;script language="javascript"&gt;
   function hidePopup()
   {
       $find('MyModalPopupExtender').show();
   }
   function hidePopup()
   {
       $find('MyModalPopupExtender').hide();
   }
&amp;lt;/script&gt;
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-6071327409485301357?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/6071327409485301357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=6071327409485301357' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/6071327409485301357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/6071327409485301357'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/01/show-and-hide-modalpopupextender-from.html' title='Show and Hide a ModalPopupExtender  from javascript'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4681772286990545567.post-6045819060039258683</id><published>2007-01-30T21:39:00.000+01:00</published><updated>2007-05-19T23:45:24.027+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Asp.Net'/><title type='text'>Asp.Net ViewState</title><content type='html'>&lt;div class="otherLanguage"&gt;&lt;a href="http://hockeswe.blogspot.com/2007/01/aspnet-viewstate.html"&gt;Swedish version of this entry&lt;/a&gt;&lt;/div&gt;A good article explaining ViewState in Asp.Net.
&lt;a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx"&gt;http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx&lt;/a&gt;

Some of the interesting titbits:
&lt;ul&gt;&lt;li&gt;When a control is tracking ViewState, items changed in the ViewState will be marked dirty. Only dirty items in the ViewState StateBag will be serialized to the hidden &lt;span style="font-family: courier new;"&gt;__VIEWSTATE &lt;/span&gt;field.&lt;/li&gt;&lt;li&gt;Controls starts to track ViewState after the it's &lt;span style="font-family:courier new;"&gt;OnInit&lt;/span&gt;.
&lt;/li&gt;&lt;li&gt;The page's &lt;span style="font-family:courier new;"&gt;OnInit &lt;/span&gt;is called after all controls' so at this stage all controls are tracking viewstate.&lt;/li&gt;&lt;li&gt;Data bound during the page's &lt;span style="font-family:courier new;"&gt;OnInit &lt;/span&gt;and &lt;span style="font-family:courier new;"&gt;OnLoad &lt;/span&gt;will go into ViewState since the control is tracking view state. This means, don't set properties on controls in a page's &lt;span style="font-family:courier new;"&gt;OnInit &lt;/span&gt;and &lt;span style="font-family:courier new;"&gt;OnLoad &lt;/span&gt;if you don't want it to go into viewstate.&lt;/li&gt;&lt;li&gt;Properties set on a control during the page's &lt;span style="font-family:courier new;"&gt;OnPreInit&lt;/span&gt;, before controls are tracking view state, will not go into ViewState. This can be used to fill controls with data that's easy and cheap to get on every postback.&lt;/li&gt;&lt;li&gt;When dynamically creating controls (for example in &lt;span style="font-family:courier new;"&gt;CreateChildControls &lt;/span&gt;in a custom control) set all properties &lt;span style="font-style: italic;"&gt;before &lt;/span&gt;adding the control to the control collection, or else you are at risk of that the control is already tracking ViewState.
&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4681772286990545567-6045819060039258683?l=hocke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hocke.blogspot.com/feeds/6045819060039258683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4681772286990545567&amp;postID=6045819060039258683' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/6045819060039258683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4681772286990545567/posts/default/6045819060039258683'/><link rel='alternate' type='text/html' href='http://hocke.blogspot.com/2007/01/aspnet-viewstate.html' title='Asp.Net ViewState'/><author><name>Håkan Canberger</name><uri>http://www.blogger.com/profile/07785350579880064843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
