MCT Day at TechEd

TechEd is coming up. Scary thing is my schedule is about 75% booked - and not with actual sessions. I'll talk more about the stuff I'm involved with over the coming weeks and during TechEd.

The interesting thing I got today was the Agenda for “MCT Day” - which is the Saturday before the conference for MS Certified Trainers. There are lots of interesting things on the agenda, but the person I'm most looking forward to speaking is Richard Klees.

Richard does the training for a lot of MS presenters and is very well recognized as the speaker of speakers, the trainer of trainers.. He's doing some time with each TechEd speaker again this year. Just hearing him talk for an hour is going to be a lot of fun.


VS Live Party

We threw a party on Thursday night after VS Live Toronto to help blow off some steam. VS Live in Toronto was a good time. A few people agree.

  • Jay Roxe was one of the speakers and joined us for a night on the town.
  • Datagrid Girl Marcie Robillard too. Turns out we share some PowerBuilder history from back at her days with Anderson Consulting. Marcie was also one of the speakers. I watched her presentation to see if I could pick up any public speaking tips, but I left learning some technical things. A) You can do a DataSet.ReadXml and pass it an url, not just a filename. B) The file/url you point it at can be any reasonably formed xml document - not just a previously saved dataset. She loaded the RSS feed from the Code Project. Cool. In practice, an untyped DS does lots of inferring which can be problematic so stay tuned for a fully fleshed out tip on doing some typed DS loading of XML docs.
  • Mike Flasko has posted some pictures from VS Live. Mike is on the Imagine Cup Canadian winning team. Be sure to check out the sub folder from our party. Elisa Johnson and Jason Kemp also from the team were there. A very nice group of people I was glad to meet.
  • Thanks to Billy Hollis, Keith Pleas, Paul Yucknovic??, Rob Windsor, David Totzke, Chris Kinsman and of course the rest of the ObjectSharp clan for coming out on the town.


MSDN DevChat - ASP.NET Whidbey - May 11, 2004 - Toronto - -19

On May 14th at 1:00 pm EDT, Dave Lloyd, one of our senior consultants is giving a webcast on the upcoming version of ASP.NET, codenamed Whidbey. To get more information or to register for the webcast, click here

Uninstalling Whidbey PDC Preview

For anyone else who received the recent Whidbey 2005 preview. And thought they would uninstall an older version of Whidbey. Here is what happened when I did it.

  1. I un-installed Whidbey.
  2. Then I had to separately un-install:
    • Microsoft .NET Framework 1.2
    • Microsoft Visual J# redistributable Package 1.1
  3. Then to get Visual Studio 2003 working properly again, I had to reinstall:
    1. Visual Source Safe
    2. MSDN Library

And everything seems OK so far.

Building Maintainable Applications with Logging and Instrumentation - May 10, 2004 - Toronto - -20

Barry Gervin participated in an MSDN webcast last week talking about logging and instrumentation. Below is a summary of his presentation, and to the right you will find the accompanying slides and materials. You can also view the livemeeting recording here.

In this session we'll cover the world of logging and instrumenting your application. We'll discuss the various .NET framework components as well as higher level services as provided by the Exception Management Application Block, the Enterprise Instrumentation Framework and the Logging BLock. We'll discuss the various issues with persisting information in file logs, the event log, and WMI Performance Counters. We will also compare other alternative technologies such as log4net. We'll also discuss best practices for loging and instrumenting your application and provide some considerations for when and where it makes good sense to instrument your application from experiences in the field.

RSS Feeds and DataSets

So as I write this at 1:10 in the morning, I have just finished beating my head against a fairly hard wall.  The task was to load an RSS Feed into a DataSet.  Then once in the DataSet, the feed could be bound to a Datagrid, a DataRepeater, etc.  The plan was simple.  The strategy sound. Or so I thought.

"No plan survives contact with the enemy." -Field Marshal Helmuth von Moltke.

While I suspect that many of you are aware of the quote, it´s place in the process of strategic is frequently forgotten.  The quote is intended to remind strategists to set broad objectives and seize unexpected opportunities when they arise. Of course, in this instance, I´m using the more pessimistic “stuff happens“ meaning that is more commonly ascribed to the quote.

So I naively start the process by creating a DataSet object and using the ReadXml method to build it.  Due to the foresight of the .NET Framework designers, I can simply pass the URL to the RSS Feed as a parameter.  Sweet.

But then I run into a snag. Or, to put it another way, Moltke proved his prescience. Within ReadXml, a DuplicateNameException is thrown. The specific message was  “A column named 'comments' already belongs to this DataTable.“ After an examination of the RSS feed, I discovered that the Slash RSS module uses a Comments tag. In the RSS feed, it is properly namespaced, but the namespace is not recognized by ReadXml.  So the Comments tag in RSS clashes with the Comments tag in Slash RSS.

The solution to this problem is not as clean as I would have liked.  In my ideal world, there would be a way to limit the namespaces that are loaded into the DataSet.  Perhaps using the XmlNamespaceManager, for instance.  But for all the Googling that I did, there doesn't appear to be any solution down this alley. So instead I turned to a kludgey (from my perspective) method that involves transforming the RSS feed using XSL.

My next problem immediately followed this solution.  When I processed the transformed RSS feed, another exception was thrown.  This time it was a ArgumentException that read "The same table (p) cannot be the child table in two nested relations.". Back to the RSS feed we went.  What we saw was that if the post was XHTML compliant, then a separate <Body> block was contained within the post.  In this <Body> block was the post complete with the various markup tags (like <p>) intact.  This differs from the normal format of the post, where the angle brackets surrounding the tag are converted the &lt; and &gt;. The result was that ReadXml was choking on the fact that <P> existed in to separate items.

Back to the XSL, where I excluded the <Body> block from the RSS feed.  Now my XSL file looks like the following:

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl=""
:xhtml="" >

    <xsl:template match="*|@*|comment()|text()">
<xsl:apply-templates select="*|@*|comment()|text()"/>

    <xsl:template match="slash:comments">
xsl:apply-templates select="*|@*|comment()|text()"/>

    <xsl:template match="xhtml:body"></xsl:template>


Mission accomplished.  I now have a DataSet that contains the necessary information from an RSS Feed.  Next up is to actually bind it to the desired control.  Haven't gotten around to it yet, but I'm hoping that it is much easier.  It certainly shouldn't be much more challenging.

Setting focus back to the control that caused the PostBack in an ASP.NET Form

SmartNavigation can be set to true on your ASP.NET webform so that when postbacks occur , the page when rendered back to the browser, will navigate back to the control that caused the postback.

But SmartNavigation can be problematic especially when dynamically loading controls onto your webform.

Therefore if you have SmartNavigation turned off = false, below is a piece of code that you can call from your webform  that will add javascript to your page, to automatically navigate back to the control that originally caused the postback.

I tested the code against IE6 and Netscape 7.1.


  /// This method will take passed webPage, and find the control that caused the postback. If it finds
  /// one it will set javascript on the page to set focus to that control

  /// The web page
  public void SetFocusPostBackControl(System.Web.UI.Page webPage)
   string[] ctlPostBack;
   ctlPostBack = webPage.Page.Request.Form.GetValues("__EVENTTARGET");
   if (ctlPostBack != null && ctlPostBack.Length > 0)
    string ctlUniqueId;
    ctlUniqueId = ctlPostBack[0];
    System.Web.UI.Control findControl = webPage.Page.FindControl(ctlUniqueId);
    if ((findControl != null) &&
     (findControl is DropDownList ||
     findControl is TextBox ||
     findControl is RadioButton ||
     findControl is RadioButtonList))
     string ctlClientId;
     ctlClientId = findControl.ClientID;
     string jScript;
     jScript = "<SCRIPT language=\"javascript\"> document.getElementById('" + ctlClientId + "').focus(); document.getElementById('"
     + ctlClientId + "').scrollIntoView(true) </SCRIPT>";;
     webPage.Page.RegisterStartupScript("focus",jScript ); 



Developing an ASP.NET Framework From a Windows Forms .NET Perspective.

A couple of months ago, I had to quickly develop an ASP.NET framework.
I incorporated parts of a Windows .NET framework that I had previously worked on. The basic
premise being that a Windows .NET Form and an ASP.NET WebForm are both event driven 
and have controls such as buttons and dropdowns.

There were two basic steps in developing this ASP.NET framework.

1) Creating Ancestor code behind pages for all the code behind pages used in the project: 

a) public class WebFormBase : System.Web.UI.Page -> For the Web Forms
b) public class WebUserControlBase : System.Web.UI.UserControl   -> For the Web User Controls
When a Webform or Web UserControl needs to be created, their code behinds inherit from the custom base class:

public class  OrderWebForm : WebFormBase
public class  ProductWebuserControl : WebUserControlBase

I think the above is a pretty standard thing to do.

The only thing I really did a little bit differently was to raise more events up to the descendent pages such as:





In this way the descendent code has a chance to do some work before and after the code in ancestor.

2) All server side controls used on a WebForm or Web UserControl are inherited from the standard Microsoft Web Controls, or a third party control:

public class MyWebButton : System.Web.UI.WebControls.Button
public class MyWebMenu : Infragistics.Web.UI.UltraWebMenu
etc. etc. As you know there are many more. Hyperlink, Label, DataList etc.

For this framework thats pretty well it, in a nutshell.

This has really paid off for the future development work, because server Side controls can now implement custom interfaces,
such as :

Then in the base classes for the code behind for the WebFormBase or the WebUserControlBase, all the code is there to handle translation  of pages to French or English or to disable or enable or disable controls automatically depending on a custom property put on the Web page called Enabled. Other things that have been built into the framework are resource file management, session management, navigation management and a custom help button that launches another browser with some help.

Closing a form before it shows

I'm working on a smart client application at the moment. One of the forms, under certain conditions, launches a wizard to gather information from the user.

From the users perspective they open the form and the wizard displays. If the user hits cancel, I want the wizard to close and the form not to show.

So what is the best way to do this. There is no cancel in the FormLoad event. If you try to close in formload an exception is raised:

Cannot call Close() while doing CreateHandle().

I asked Google and found one solution. Controls have a Public Event, VisibleChanged that fires when the visible property is changed. In this event you can call the forms Close method.

This works fine with one side effect, the form shows for a split second then closes.

This will suffice, but if anyone knows a better way to do this please let me know.



OpenSource Project for Testing Microsoft Software

Over the past few months, when I question how something works in the .NET Framework (or when somebody asks me).....I have been creating NUnit tests to verify the behaviour of some class and/or methods in the .NET Framework. Initially it is just to observe the behaviour or verify some assumptions, but by the time I'm finished, I usually inject various Assertions into my tests to tighten them up. These now serve as a test bed for me moving to a new version (or even old versions) of the .NET Framework. I can answer the question: Are any of my assumptions about how the 1.1 framework works broken in 1.2? 2.0? 9.0? etc.

I'm building up a nice collection and I might publish my work. But it struck me that this could be an open source project. In fact, I think it should be an open source project and I think it should be started by Microsoft....and not necessarily for the .NET Framework alone - but that would be an easy place to start.

Microsoft has faced increasing pressures over security and quality of their software - to the point that they've actually made windows source code available to key customers, governments and MVP's. I think that's a bit risky if you ask me. I think it is also a bit hypocritical to point the finger at Linux for being “more hackable because source code is available“ but at the same time make your own source code available to the chinese government.

But why not publish the source code to unit tests (say NUnit fixtures) in an open source format for the community to contribute to. When one of these security firms finds a hole in some MS software, they could create an NUnit test to expose it and submit it to Microsoft to fix, and then make the code for that NUnit test part of the open source project.

Instead of publishing source code, which is really meaningless to give people any kind of comfort in the code, publishing unit tests is publishing assumptions and expectations about what software is supposed to do and how it is supposed to behave. I would think this would become more important over time especially moving towards WinFx and Longhorn.