Fixed IE 6 style sheet issue

Published 07/06/2008 by Henry in CSS

A colleague of mine (Geert) pointed out this site did not work well under IE6.
I fired it up and sure enough, it did not show the blogposts, all was black.
I also tried in Firefox, but that worked nicely.

I went through my stylesheets, while trying out stuff in IE 6.
It turned out to be 1 line that worked nice in all browsers, but not in IE 6, I removed it and now I'm cool again.

Thx Geert, for pointing this out.
Goes to show, trying out as much browsers as possible when building web apps is no luxury!

Henry Cordes
My thoughts exactly...

ASP.NET MVC Preview 3 released!

Published 31/05/2008 by Henry in ASP.NET | C#
Tags: ,

ASP.NET MVC Preview 3 is released. You can download it from here:

I took the following quote from ScottGu's blog which is a dutch translation!
Je kan hier een geintegreerd pakket van de ASP.NET MVC Preview 3 setup downloaden. Als je dat wil, kan je ook de ASP.NET MVC Preview 3 framework broncode en de framework unit tests hier downloaden.
Which means something along the line of:
You can download an integrated ASP.NET MVC Preview 3 setup package here.  You can also optionally download the ASP.NET MVC Preview 3 framework source code and framework unit tests here.

The way Microsoft is open about the code they write, is awsome to me.
The 'ScottGu teams' really turning the game upside down, IMHO it is so cool and insightfull to look at the way the MVC Framework team sets up the framework. The opportunity to look at their tests is another learning experience to me.
So download an learn, is what I say!

Henry Cordes
My thoughts exactly...

External js file and CRM

Published 27/05/2008 by Henry in AJAX | CRM | Javascript

While doing a project where MS Dynamics CRM  is used a lot of customizations are performed by JavaScript.
Usually the way to it is to perform some JavaScript actions in the OnLoad of the Page.
MS Dynamics CRM has a extention point, where you can control the OnLoad of Detail Forms by entering JavaScript.

Now when you need to deploy your CRM configuration to more than one system (like we do at my project, it is sold as part of a product), you want to use a centralized Javascript file so you can change your url's etc. all in one place.
To do this (unsupported by Microsoft!) I learnt the following technique from CRM Specialists:

First technique

   1:  var script = document.createElement('script');
   2:  script.language = 'javascript';
   3:  script.src = '/_customscript/customscript.js';
   4:  script.onreadystatechange = OnScriptReadyState;
   5:  document.getElementsByTagName('head')[0].appendChild(script);
   7:  function OnScriptReadyState()
   8:  {
   9:      if (event.srcElement.readyState == 'complete')
  10:     {
  11:          // Perform onload script
  12:          //Doit();
  13:      }
  14:  }

Listing 1

The drawback with this technique is that the first time CRM loads (and every time the cache is empty) the script is not executed. Leaving the user to think the application does not work. After some time it really annoyed me, so I started to ask uncle Google again for a solution. I found the following on

What this guy does is doing an AJAX call, to get the js file.
Next he loads the javascript as a string, eval() it, and imports all functions found into the current namespace, so you can access them.

It needs functionnames a-z, it cannot handle numeric values in the name of the function, but i will fix this before I will use it.
Otherwise I think it rocks! Async technique (no first time drawback)

   1:  function load_script (url) 
   2:  { 
   3:      var x = new ActiveXObject("Msxml2.XMLHTTP"); 
   4:'GET', url, false); 
   5:      x.send(''); 
   6:      eval(x.responseText); 
   7:      var s = x.responseText.split(/\n/); 
   8:      var r = /^function\s*([a-z_]+)/i; 
   9:      for (var i = 0; i < s.length; i++) 
  10:      { 
  11:          var m = r.exec(s[i]); 
  12:          if (m != null) 
  13:          {
  14:              window[m[1]] = eval(m[1]); 
  15:          }
  16:      } 
  17:  } 
  19:  load_script("/_customscript/customscript.js"); 
  21:  //perform onload scripts
  22:  //DoIt();

Listing 2


As I mentioned numbers in the functionname caused the code to fail. So I changed the regex pattern in line 8 from listing 2 into:

   1:  var r = /^function\s*([a-zA-Z_0-9]+)/i; 

Listing 3

With this regex pattern functions with numbers in the name also are added to the namespace. I added the uppercase A-Z not because functions with uppercase characters in the name where not added, but as a best practice. also you can never be sure browsers keep on using IgnoreCase as default setting.

As you can read in the comments, Marc-Andre uses the following pattern:

   1:  var r = /^(?:function|var)\s*([a-zA-Z_]+)/i; 

He wants some vars (which he uses as constants) to be added to the namespace also, maybe I would add the 0-9 here also. anyway, I think it is a good suggestion to mention here.

Addition 2:

Steve Le Mon made a very good suggestion and tried out a few things, he found a way around the parsing of the functions and/or vars and adding them to the current namespace.
I tweaked his code a little bit and ended up with the following:

   1:  function InjectScript(scriptFile)
   2:  {
   3:      var netRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
   4:"GET", scriptFile, false); 
   5:      netRequest.send(null); 
   6:      eval(netRequest.responseText); 
   7:  }
   9:  InjectScript('/_customscript/customscript.js');
  11:  //CallFunctionInExternalFile(); 

Listing 4

This technique removes the overhead of the parsing of the functions and vars so will perform faster.

Henry Cordes
My thoughts exactly...


When I migrated my blog over to a new provider and blogengine, I lost some images,replaced them using VS2010, so some screenshots look 'newer'.

Series  - Create a UserControl with Silverlight 2.0 Beta x  

Part I   - Create a UserControl with Silverlight 2.0 Beta 1 (this post)
Part II - Create a UserControl with SilverLight 2.0 Beta

Wanting to know what all the hype is really about, I started to think about creating a web application with Silverlight.
Before I will create an application, my idea is to start of with a UserControl. A really simple one too. For the application I am going to maybe be building with Silverlight, I need a UI component to choose the gender of a person.
You could use two radiobuttons, make them a member of the same group and we're off. But with Silverlight we can try a more graphical approach, maybe a more intuitive control. I want to create a control that has the Male and Female Symbol that are clickable, through clicking on a symbol you select the gender.

I installed:

  • Microsoft Expression Design
  • Microsoft Expression Blend 2.5 March 2008 Preview
  • Microsoft Visual Studio 2008
  • Microsoft Silverlight Tools Beta 1 for Visual Studio 2008

First thing you learn when starting to use this technology is that you really need a designers eye on things. So if you are not a creative person, that likes designing stuff, maybe you need a designer to do it for you.
We are going to try to do the design ourselves for now.

Create Solution and projects
First I Fired up Visual Studio 2008. I created a new Silverlight Application (so it is easy to try our control out).

Create Silverlight Application

As soon as you click OK, you are presented a choice, because Silverlight will be hosted on or inside a web page, you have to choose from the following options:

  1. Create only the Silverlight app and let Studio generate an HTML page for you to test the app with (only in bin/debug)
  2. Add a Website project to your solution
  3. Add a Web Application Project to your solution


Select hosting application type

I choose option 3. a Web Application Project. Now I got two projects inside my solution. I right click on the Page.xaml file and choose "Open in Expression Blend"


Open in MS Blend

Rightclick on the Silverlight project file and choose "Add New Item..." from the menu

Add new item to Silverlight application project in Blend Add New Item

Select UserControl as template and give the control a name.

Give the xaml file for your UserControl a name New Item

Rightclick in the area named: "Objects and Timeline" in the left side of Blend, on the UserControl and select Rename, give the control a name (GenderChoose), it cannot be the same as the name you gave the .xaml file (this is confusing, because the New Item dialog suggests you name the Usercontrol, but all you do is name the xaml and these names both must be unique.

Rename the UserControl in blend Rename Control

Because the background of the LayoutRoot is white  We need to change it to transparent, we do this by selecting the LayoutRoot inside the UserControl