Thursday, March 27, 2008

Old Code Part 4: I thought it was a Joke

Question Mark image by jhhwild on flickr About three years ago some senior executives at our company were in town for a big planning meeting.  As frequently happens during these times the entire office went out that night to show the visitors a good time.  During that get-together, the director of our office came to me with a question: Is it possible to have our web based application open a desktop app on the server and have a user over the web control that application.  I basically and politically said no, with the standard disclaimer that with enough time and money anything is possible of course.  So I thought that was the end of it.

The next afternoon I'm sitting at my desk working and in walks the director who promptly asks how I'm doing on making the web app launch and use the other app.  I was kind of stunned as I thought the topic was done but I start researching at the point.  Pretty much everything I can find either says it can't be done or you are stupid to even try.  The best answer on Google Groups was to quit working at a place with such unrealistic expectations.

So I took my findings to my boss who says "Yea, that's what I'm hearing from other people too, but you still need to make this work."  And with that I went to work on a prototype.

Over the next week I learned about using p/invoke to launch a windows app.  It was a little odd, being a web developer but within a week I was able to launch the windows app and send keystrokes to it.  Having proven that at least that much was possible my boss then assigned a couple more developers to work on this.  Luckily one of these developers had a windows background and so he took care of the lower layer.  We then had the prototype actually scraping the windows app and passing the values up through a windows service, to the web app.  At that point the web app would convert the values into screen coordinates and control types, and populate then with values.  We even had the app sending each keystroke from the client browser to the web app via AJAX and whenever the windows app updated itself we would refresh the screen to update the visible controls.  It would also spawn multiple instances of the web app, one for each user.

We had accomplished what we had thought was not possible!

When we showed this to the director, he was glad that we got it to work but to me didn't seem as impressed as he should have been :).  He did go off and tell the Japanese sponsors of the project about it though and before we knew it we were on a 8:00PM WebEx with Japan showing off our prototype.  Before this call got started we were under the impression that it was going to be just a couple of the executives from the earlier meeting in Canton.  When it actually got started however, it sounded like an entire conference room full of people.  We ended up finding out that the development team in Japan that had written the windows app had been tasked with this same goal earlier and had tried and failed.  I would NOT have wanted to be in that room when the inferior American developers showed it working :).

In the end, the project that we had proven possible was moved offshore where it was morphed into something else entirely.  At least we knew we had done it, and now so do you :).

Wednesday, March 26, 2008

Review: Cleveland C#/VB.NET SIG 3/25

sig_logo Last night was the March meeting of the Cleveland C# / VB.NET SIG.  It was really the February meeting as well since that was delay multiple times due to weather, gotta love Ohio.  This was my first trip to this particular group and I really enjoyed it.

The topic for the night was SQL Server 2008, with Sam Nasr as the presenter.  Since he is also the leader of the SIG it was pretty much all Sam, all the time.  Since SQL Server is still only a CTP much of the information is subject to change but it does look like they have added a bunch of new features that will make development a little easier.  Nothing ground-breaking, but some niceties.  My favorites are some of the new datatypes such as Date, Time and HierarchyId.  I've been wanting them to have a separate Data and Time type for a LONG TIME.

This crowd is a lot more interactive and the group at the BA hosted .NET SIG.  During this presentation there was a lot more discussion, and not just asking and answering with the presenter.  Sometimes a question would be answered by another person (or people) from within the group.  It made for a very good experience. 

Several things come to mind that may cause such a difference in the group dynamics.  First, the average age of this group is probably ten years older than of the other one.  Typically with age come experience and more of a willingness to be "out there" where others can see/hear you, both of which increase the likelihood of speaking up in a crowd. Another factor could be that this crowd and the venue itself were smaller.  The more intimate setting also makes it more comfortable for people to be themselves.  I would name as a third factor that Sam actively tried to engage the crowd, and while that is a needed aspect of interaction, presenters at the other SIG also try this, so although this is a good and needed thing, it doesn't set this group apart. 

One more thing that I would name as different and good is that it felt more informal.  Sam sat during much of the presentation, granted it was partly to reach his laptop, and that help the crowd feel as equals.  Also instead of just jumping into the presentation there was a little bit of a conversational feel to the non-presentation aspects of the night.  Even the presentation felt that way.  I can't point to one thing in particular that made the night different but I think all of the above items contributed to a better experience.

After the presentation was over Sam had a few of us come up and announce Cleveland Day of .NET.  We talked it up and asked people to register and to ask their bosses to sponsor, I think it went over well.  Sam also announced that I'll be doing next month's talk on Silverlight 2.  I guess it's too late to back out now.

And there was an after-party at the Winking Lizard on Rockside again.  There were about six of us there, ok, exactly six, and it was a fun time.  We were talking about how old Mike is :) and what we started programming on and such.  I came to realize that I'm nearing old.  Ick.  The chat was so fun though that before we know it the clock said 11:00PM and we split up to get sleep before work.

So it was a good night, good crowd and I look forward to next month.

Thursday, March 20, 2008

Silverlight 2: User Controls and Other Tips

Silverlight logo So I've started working in Silverlight and am completely blown away by it's power and ease of programming.  I'm not saying that there isn't a learning curve, there is with any new technology, but this one isn't too bad.  To be honest the hardest part of Silverlight 2 is finding information on it.  So with that said I'm going to pass on some of what I've learned over the last couple weeks.

First, the absolute best resource online currently is the forums over at, there are people on there that really know their stuff and are happy to help out others.  You do need to register to use the forums but the same login/password you use at will work here as well.  I also recommend subscribing to the RSS feed of the latest blogs related to Silverlight, tons of good, knowledgeable people get cross-listed there.

So what am I working on?  First, this is what the project sponsors asked for:


As you can see it's boring.  No one cares about look in this application but still, we saw that and immediately thought of a nicer way of doing it.  So we convinced my manager to allow me to build a prototype screen for the feature using Silverlight 2.  He even gave the approval before the beta for Silverlight 2 was released.  So this is what I built: (Disclaimer:  If anyone is an NEC Unified Solutions customer the following screenshot is not in and may never be in a released product)


Look a little nicer eh?  Basically it reads an XML document at runtime that it downloads from an ASP.NET application and then parses that data to create a series of controls.  The controls are one to four Stacks which can contain one or two Modules, each of which contain four Units.  The Stacks, Modules and Units are all specific to the application being built, which happens to be a piece of a PBX management application.  These are represented in the Silverlight application using custom User Controls defined for each piece.  The host application will have business objects that also relate to each of these Silverlight User Control classes.  Each of these user controls (Stack, Module and Unit) are added at runtime based on the downloaded XML document.  There are also more controls at a lower level and a couple of controls that are nothing but forms but for now lets concentrate on those three controls.

I'm not an expert by far, yet, but I have learned quite a bit about them and am very impressed.  In many ways User Controls in Silverlight are much more powerful than their ASP.NET counterparts.  You don't need to worry about state between actions for instance, this one piece took me a little while to figure out but once I did it is powerful indeed.  So here goes, some tips and pointers on Silverlight 2 User Controls.

First there are a couple of things you need to know for the code to make sense, LINQ and the way we're accessing global resources.


The normal XML namespace is not available in Silverlight so if you want to work with XML, you need to learn LINQ.  For me this was probably the hardest part of creating the prototype.  I've created and consumed many a XmlDocument in the past so moving to XDocument instead was a big step, it all looks foreign to me.  I struggled through it though and made it work, though I doubt someone that really knows LINQ to XML would think this code is "pretty".

You will be seeing LINQ to XML used in a few of the below samples but here is a taste:


In the above sample I am parsing the XML displayed below and returning a collection of slot elements.  It's different but makes a lot of sense one you get the hang of it.slotxml 

Accessing Global Resources

Another issue that needed addressed is that of accessing global resources.  This is one area where I had to go to the forums for help.  I'm not sure if the answer I received and thus the approach that I took is the recommended approach, but it does work.  Basically the approach is to take create a singleton class that is loaded during initialization and then can be accessed ad modified from any level.


You will see this object used in some of the later code samples, at least now you will know what you are seeing.  It is all very simple, as is everything in Silverlight, once you figure out how to do it.

Now to the User Controls. 

User Controls are Real Objects

This is something that on the surface sounds like a no-brainer but when you really understand what it means is one of those things that changes the game.  For those of us coming from the web world pretty much all we have ever known is stateless programming.  All of our objects are one-time use and then you load it again if you need it again.  ASP.NET tried to mask this somewhat but the basic fact still remained.

With Silverlight 2 though any properties that you assigned values to still have those values when you next look at that object.  That sentence is a little hard to follow so let me try to explain. 

  1. Add custom properties to your new User Control when you create it.
  2. At runtime assign values to those properties.
  3. When responding to events at a later time those properties still have the value that was assigned.

The above doesn't sound that big but when you have multiple instances of the user control and each instance has unique values assigned to it's properties, the usefulness becomes much more apparent. 

To illustrate this here is a custom User Control I created for the prototype.  This is one of the simplest user controls but it illustrates the points.unitxaml

As you can see it has a very simple presentation, nothing but a square with some text on it, both of which call the same click event handler.  Now for the (truncated) code behind for that same control:rawunitcode

The class is derived from UserControl and defines a number of properties.  It also has a second constructor which initializes those same properties.  Nothing unusual here.  Here is an event handler accessing the properties declared above:rawunitevent

In this sample you can see that we are using the GlobalVariables singleton to obtain a reference to the root element of the XAML.  We then are using some of the values from the active instance of the Unit class to initialize an editable form, even passing in a reference to itself.

Programmatically Adding User Controls

For many dynamic applications you will not know at design-time the exact number of a given piece of your application.  This creates the need to add a given number of said element at run-time.  Enter Programmatically added user controls.

Adding a user control from code is quite simple and very similar to doing the same operation in ASP.NET.  You basically add the new user control to the children collection of some parent object.rawpage

After seeing how the controls are added, the code above of the event handler accessing the assigned properties should make a lot more sense.  You don't have to do any special coding to determine which object was clicked, as it is the actual object you created earlier.  This is a wonderful thing for all of us ASP.NET developers used to loading objects on each postback.

In a real world deployment there may be more logic happening here but this is all it takes to do this.  As you can see it is as simple as creating an instance of the control and then adding it to the parent.  One thing you may have noticed is the use of LINQ to XML, there is a reason for that that I will cover next.

Other Tips

  • Don't put a name on the root level control in your User Control or there can be only a single instance of it in the Silverlight application.
  • Learn LINQ.  I know I already mentioned this one but if you are going to be doing much Silverlight development it is a good thing to know.
  • Use Generic collections.  The Silverlight version of the CLR does not support the "old" collection types like ArrayList so get used to working with the new Generic collections like List<>.  Personally I prefer these anyway.

Final Thoughts:

So this was my first real taste of Silverlight development and all I can say is "WOW".  I already thought that this was going to be a game changer and now I am completely convinced.

This post has become a little longer than I had intended but I feel it is all good information for the ASP.NET developer getting started in Silverlight.  I will be posting more on Silverlight, and I'll also be giving some talks on it that will be announced in the near future.  This is an exciting time to be a web developer!

If you would like more information on this please comment on this post or ask me by another means.  I'll also be giving a presentation on April 22nd for the Cleveland C#/VB.NET Special Interest Group and again on May 17th at Cleveland Day of .NET with this same application as the base for the demos.

kick it on

Cleveland Day of .NET

Cleveland Day of .NET Logo Finally!

Cleveland is finally getting a real one-day, free, community driven, developer conference.  That's right, clear your calendars for Saturday May 17th as there will be an all day multi-topic, multi-session conference for all of us.  The website ( will be open any day now and will start accepting registrations immediately. 

We are also accepting proposals from anyone that would like to present one of the sessions.  We most likely will have more proposals than available sessions but don't let that discourage anyone.  So polish up your best content and send it to

We also need sponsors to help offset some of the costs of putting on a free event like this.  If any of you would like to sponsor or would like us to contact your employer please drop us a line to

So head on over to, register and show up and learn a lot!

Monday, March 17, 2008

Review: Cleveland Microsoft Launch Event 3/13

Heroes Happen Here logo On Thursday was the Microsoft's launch event for Visual Studio 2008, SQL Server 2008 and Windows Server 2008.  If you don't know what those three things are you might as well stop reading now :).

The event was held at the downtown Marriott, right off of public square in Cleveland.  If you haven't been to Public Square for a while, it was a big pile of snow and construction.  Mud, no working stop lights, half of the sidewalks not even shoveled.  Was a great impression for Cleveland overall.  Yes, that was sarcasm, get used to it, you will be seeing it again.  Once inside (the correct building) though it was fine.  The meeting room for the developer track was fairly large, someone said 750 seats, and it was full at the beginning.  Chairs were a little too close together for my taste but oh well, it worked.

Supposedly there were four sessions but really it was more like three as there was no real delineation between the first two.  Jeff Blankenburg and Brian G. (Developer Evangelist from Chicago) tag-teamed the first two sessions with Brian covering the marketing slides and Jeff doing the demos.  It worked pretty well and they are both very engaging speakers, not people to just read from a static script.  Jeff's demos might have been easier for him if his mouse was a little closer to the same level as his laptop.  The podium was cramped so there was probably a 18" drop to the mouse.  I'll bet that was comfortable.  The demos went well with only minor glitches that were easily resolved.  We all got a chuckle, well, outright laugh really, when we learned that apparently the AJAX password strength checker at it's default settings thinks that "password" is a strong password. :)

The second half of the developer track was done by Bill Steele.  Bill didn't let us down with his usual blend of humor and presentation skills.  My favorite, and the crowd's, was when he showed us how to use a semi-colon at the end of a VB line.  It's simple really.  You have to prepend it with a ' (for those that don't know, that is a remark char in VB). =)

I know I haven't covered the content but you can get all of that online at the Heroes Happen Here virtual launch event.  What I will say about them is that if you don't know anything about VS 2008 yet then you need to go watch the presentations to get a feel for the new features as they are very nice.  It was worth my time to go and miss most of a day's pay, even before the free software, which is nice btw.

Before the event I spent probably 30 minutes talking with Brian Prince about organizing community driven events.  He gave me quite a bit of good advice which I have passed on to some key people already.  If any of you don't know we are planning an event which will be officially announced later this week so check back in a couple of days for a cool announcement.

Wednesday, March 12, 2008

Review: Cleveland .NET SIG 3/11

Last night was good for a lot of reasons, but was lacking in a few others.  First the good.

The speaker, Miguel Castro, was great.  He is a very energetic speaker with a lot of relevant experience.  His talk on URL rewriting using Module and Handlers was informative and interesting.  The presentation had the right combination of details and high level overview to both demonstrate the "why" and the "how" of URL rewriting.  He included multiple methods to achieve the results and gave advantages and disadvantages to each method.  Examples were clean and to the point as well, not cluttered with things that he admitted you would need in a real-world app (like error handling, caching etc.), but demonstrated the needed points.  I learned a ton and definitely plan to see him talk again if he's ever in the area.  Since this was his first trip to Ohio though, I don't expect to see him in the area again any time soon :).

After the event a group went down to the Winking Lizard for drinks and conversation.  That is where the good networking/community building took place.  There were about a dozen people total went to the bar, which isn't too bad since this was only the second or third time it was done.  It was a good group too, Richard Broida, Jeff Blankenburg, Sarah D. (Not even going to try spell it :)), and a bunch more people came by.  We talked Day of .NET, SIG stuff, and other technical topics but basically it was a bunch of BSing.  Apparently Jeff is nearly as big a smart ass as I am, made for a fun conversation.  There was also more interest in starting a user group in the Akron/Canton area, it might be time to get that going.

Now for the bad.  At the actual SIG event the crowd was dead as usual.  Almost no interaction from the crowd.  Miguel did his best to get interaction started but the crowd just didn't get it going.  At the after-party (that's right, it was a geek after-party), there was some discussion on what can be done to facilitate a more interactive group but personally I don't see anything changing anytime soon.  If we start a group in the Akron/Canton area though I do see us doing things a little differently.

Overall I had a great time, learned a lot and met some cool new people.

Monday, March 10, 2008

How Dinosaur Web Developers Can Regain Their Shine: Step 3

Rebrand Yourself

This one some people won't agree with but with new web technologies coming so fast and each having such potential, I think it's time to specialize.  I'm not advocating ignoring the other facets of our field, just picking one and knowing it inside and out, becoming an expert in a single field of study.

There are many options:

  • Web Standards (Don't just say CSS)
  • AJAX
  • Silverlight
  • Data Access (Linq, ADO, SQL 2008, etc.)
  • Web Services

That list is not even close to complete and is focused on MS technologies but you can get an example from it on how many different ways you can specialize.  I think we should all have a basic understanding of all of these technologies, but I also think we should find one technology that we really get into and specialize in it. 

Pick something that excites you.  Something that you can really get into so deeply that it rubs off on others.  Learn this technology so deeply that your peers regard you as a true expert in it.

I know this post is short and probably incoherent but better content will be coming soon.  Hopefully.

Thursday, March 6, 2008

No Excuse for JavaScript Errors!

I've refrained from posting rants to this blog up until now but I feel that this one is very relevant to the topics discussed here.  JavaScript errors on production web sites degrade the user experience for all users!  There is no excuse for them.  At best they degrade viewer's confidence in the site, at worst there is crucial functionality that doesn't work.

I know I'm not the first to rant about this, unfortunately I most likely won't be the last either.  With the proliferation of AJAX frameworks and JSON the number of script errors will undoubtedly increase instead of decrease.  Too many web developers either don't understand JavaScript or don't care enough to make sure that it works properly.

Personally, I think all web developers should always have script error notifications turned on in their browser, even when they are just surfing.  It really makes you see how prevalent they are and drive you to ensure that your own sites/applications don't have the same issues.

mixerror These errors aren't limited to small sites either.  Click a navigation link on the website for mix08 and you will find a JavaScript error!  Inexcusable.  This is even a site promoting a conference for web developers!  If on a Microsoft conference website there are errors, how can we expect Joe Developer to do better?

Monday, March 3, 2008

Web Accessibility: What does it mean?

In the first of this series on Web Accessibility I spoke briefly on why we should care about this important topic. Hopefully people don't need reasons but in case they do what I detailed should be a gentle push in the right direction.

For this installment I'm not going to get into what the standards are but try to give developers a way to better understand the implications of following the standards or not, and how some things that might actually be OK according to the standard do not necessarily make the site user friendly to all visitors.

What does it truly mean to make a website accessible? Learning the requirements and coding your site so that it passes the validators is definitely part of the process, but to truly make your site accessible requires more of an understanding of how the alternate methods of using sites actually work. You can go through the effort of using screen readers, magnifiers, speech recognition tools and the like but since most of us are used to using the mouse, keyboard and our eyes, we will never get a true feel for what it is actually like. I'm not saying don't try the tools on your own site / application, that is a very good idea, but there are a few other ways to learn as well.

Luckily, some users of these tools that also work in the web industry have recorded videos of them using their tools and talking about the user experience. If you do a quick search on YouTube you will find many such videos, some good, some not so good, but many at least give you a taste for what it is really like.

The best ones I've found come from Yahoo:

Personally I learned a lot from these two videos and I highly recommend watching them. It really changes the way you think about web accessibility by changing it from "Meeting the Standards" to "Making the Site Usable".