Even though I’ve been doing ASP.NET for 8 years, I never realized until today that when you put a breakpoint in Application_Start in Global.asax, it may never be hit.  The reason, I discovered, is that the debugger doesn’t have time to attach to the web application before Application_Start finishes.  To get around this, you can force your application to restart after the debugger has had a chance to attach by simply editing and saving a change the web.config.  This causes the application to restart and your breakpoints in Application_Start will now be hit.

There has been some angst in the .NET development community lately as Microsoft has started putting a lot of emphasis on HTML5, especially leading up to the release of IE9.  The issues center around the overlap in capabilities provided by both technologies and Microsoft’s seemingly incongruous dedication to both.

Well, the Silverlight Team is now weighing in on the controversy on their blog here: http://team.silverlight.net/announcement/standards-based-web-plug-ins-and-silverlight/

To summarize, they are saying that software development has always required an array of tooling choices--some with some feature overlap--but that Microsoft sees different advantages and disadvantages to both HTML5 and Silverlight, and that leads ...

Fans of Internet standards, rejoice!  Today Microsoft officially brings us Internet Explorer 9 which scores a 95 out of 100 on the ACID3 test and passes the CSS Selectors Test with flying colors.  It’s worth noting that IE9’s ACID3 score is one point more than the current version of Mozilla’s Firefox, but still five points below Chrome and Safari.  Many developers will also be very happy to know that this latest offering from Microsoft implements many of the new features of HTML5!

To me, IE9 is a story of Microsoft finally starting to catch up to the other browsers, but ...

UPDATE May 4, 2011: It was brought to my attention that there was a typo in my code below, but it is now fixed.

I sometimes find it necessary to walk the visual tree of controls in Silverlight (or WPF) at run-time.  The VisualTreeHelper class provides some nice functionality for doing this.  However, using the VisualTreeHelper can sometimes require a little too much code, especially when I want to search the visual tree recursively. 

For this reason I created some simple extension methods to do the recursing for me.  Let’s cut right to the chase.  Here’s the code:

Few things are more disappointing to an ASP.NET programmer than this one line of code in a web.config:

<sessionState mode="Off" />

You probably know what I mean if you’ve ever been asked to implement user sessions for a web site that has ASP.NET’s built-in session state disabled.  In this post I will offer one simple alternative that allows you to implement user sessions on just such a web site.

Cookies Taste Better In-Memory

The secret to my solution is HTTP cookies.  In my experience, programmers are increasingly afraid to create sites that require cookies because ...

There are many ways to extend classes in .NET languages, but I thought I’d cover just a few of the more common or compelling options here.

Derivation/Inheritance

Perhaps the most common type of extensibility, certainly the most obvious, is creating a class that derives from a base class to add new functionality.  This is called inheritance and has been a part of .NET (and all other OO languages) since the beginning.

class Base
{
    public bool IsBase;

    public Base()
    {
        IsBase = true;
    }
}
          
class Derived : Base
{
    public bool IsDerived;

    public...

I was recently asked to create an ASP.NET 2.0 web site that consumed an OData (WCF Data Services) data feed.  Of course, in .NET 4.0, this would have been easy given the great tool that Microsoft has provided for us in the WCF Data Services Client (System.Data.Services.Client).  However, in .NET 2.0, this presented somewhat of a challenge.

For all the examples in this blog, I’m using Chris Woodruff’s baseballs stats feed located at http://baseball-stats.info/OData/baseballstats.svc/

I decided to write my own simple OData ATOM/XML parser.  But first, I wanted some classes to hold.  Ideally, I wanted classes that ...

The Problem

I wanted to be able to add items to a IList<T> but not at the beginning or end of the list—in order based on a sorting function I specified.  I could have used List<T>’s Sort() method that takes an IComparer<T> as a parameter, but then I would have to define a new comparer class for every class I wanted to store in the list (not to mention every time I wanted to sort one those types off of a different property). 

The Solution

Instead of this potentially bulky solution, I created a generic extension method that will ...

I was recently working on a project where I needed to open a web URL in a new browser window from a Silverlight application.  The trick was, I first needed to check some logic in code-behind to see whether the link should navigate to a page internally within the Silverlight app or externally to a web address in a new browser window.

Silverlight provides the HyperLinkButton control that allows you to set a NavigateUri and TargetName, but I needed to check my custom code-behind logic first, so that wouldn’t work for me.

<HyperlinkButton
    Content="HyperLinkButton"
    NavigateUri="http://www.google.com"...

A new version of the toolkit was released yesterday (November 2) with the following new controls:

 

- AutoCompleteBox – Born again here from the standard toolkit, this control presents the user with options to automatically complete their text as they type it.  The completion list can be dynamic or static and be provided to the control in a number of ways.


- ListPicker – This control is essentially a ComboBox.  It automatically uses either a full-screen selection popup or a expand-in-place selection depending on the number of items in the list.  This control is similar enough the ListBox that ...

Today I spoke on Windows Phone 7 Application Development at the Grand Rapids Day of .NET.  We had a great group in the session.  I was very happy to see their level of interest, excitement, and great questions.  I hope that they found the session useful. 

As promised, here are the slides and code for download:

- Download Slides (PowerPoint 2007)

- Download Sample project (VS 2010)

 

I’ve also included some links below to more WP7 resources.  Feel free to contact if you have any questions.

 

Additional Reading:

- Using Push Notification from Your Windows Phone Application

- ...

C# programmers who haven’t dabbled in VB-land for a long time may not be familiar with one of the best (and few) language features that VB had and C# didn’t for years—named and optional parameters.  With the advent of C# 4 and Microsoft’s adaption of a co-evolutionary strategy for VB and C#, this feature has finally made the jump in C#.  I thought I’d give a quick  overview of these features here for those that may not be familiar with them, and for those that have grown up with C# and may forget they are now an option.

 

Optional ...

I got some positive feedback on my recent post about binding a TextBlock’s tooltip to its own text property, so I decided to post this related follow-up…

 

Allowing your users to navigate your forms with the keyboard is a very important usability feature that is often overlooked.  In Silverlight, this is accomplished by setting IsTabStop to True on any controls you want to participate in keyboard navigation.  When the user hits the tab key, focus will cycle through all the controls where IsTabStop is True, one at a time.  Any controls where IsTabStop is false will be skipped....

Those that have been programming in WPF for a while probably already know about defining styles based on other styles.  With the release of version 3, this feature made the jump over to Silverlight as well.  Even though this is old news, as Silverlight is now on version 4, I’ve found that this feature is still little-know, and it’s so useful, I thought it deserved a post.  In the post, I’ll go over the basics of how to use this feature for anyone to whom the feature is new.

 

Why Use BasedOn

Using BasedOn to define a style allows ...

There’s not always enough room in the UI to display the entire contents of a TextBlock.  Silverlight 4 includes the a new TextTrimming feature that allows you to cut a TextBlock’s content off after the last word that fits plus an ellipsis (. . .) at the end.

When I use the new text trimming feature, I like to put the un-trimmed contents of the TextBlock into its ToolTip so that the user can still see it when they mouse over the control.

The example below shows you how you can wire a TextBlock’s ToolTip to be bound to its ...

When binding data objects to UI controls in Silverlight, one often only needs very simple, one-to-one mappings between the data property and the control property.  For example, maybe you’re binding a string property of your data object to the text property of a textbox like this:


<TextBox x:Name="tbSample" Text="{Binding MyProperty}" />


That works great if you want to display the value as-is, but sometimes you may want to format the data value or concatenate the value with other strings before displaying it.  In that case, it would be nice to be able to ...

In my previous blog post, I covered converting DateTimes between local time and UTC time.  In this post, I’ll cover a more advanced scenario: converting a DateTime from one arbitrary time zone to another.

Step 1: Don’t do it

For most people’s purposes, converting between two arbitrary time zones is a pretty rare occurrence. So before reading the rest of this article, ask yourself if there is a simpler, UTC-based solution to your problem.  Can you, for instance, assume local time on the client and convert all dates that are to be shared between users or computers immediately to ...

Update: See Part 2 of this series for details about converting to and from arbitrary time zones

What’s UTC, and Why Should I Care?

Application developers often rely on UTC (Coordinated Universal Time) to store DateTimes in a location-neutral and time zone-neutral form.  But sometimes you have the wrong kind of DateTime and need to convert it before you can use it.

 

Say, for example, you wanted to develop an application for users spread around the United States, and you wanted to stamp each record they change with a last-updated time stamp.  If you use DateTime.Now on the client ...

At Falafel, we are often called upon to create one system with several different client interfaces.  Sometimes this will include an ASP.NET, WinForms, WPF, and/or Silverlight front-end, all connecting to the same back-end server.  With this type of set up, we usually create a single solution as in the example below.

image

Usually, I see people that are in this situation set the server project as their startup project, start the debugger, and then manually launch the client application they want to debug.  However, Visual Studio (both 2008 and 2010) has a little-known feature that speeds this up by allowing you ...

I have been working on a project in Silverlight that was, until recently, debugging under the Visual Studio .NET development server.  Recently we converted this application to be hosted by IIS 7 on our development environments.  Ever since then, I’ve been getting timeout errors whenever I debug the application and halt execution using breakpoints for more than a couple of minutes.  The error dialog that appears says “The web server process that was being debugged has been terminated by Internet Information Services (IIS).

image

To solve this problem, I followed the advice given in the second half of the ...