September 2007 Entries

Silverlight Event Tokens

Events are easy to add and remove when using the CLR and C#. Just sprinkle some += and -= in the right places and the runtime does the rest. Silverlight programming with JavaScript is a bit different, however, and although the addEventListener and removeEventListener appear similar to a DOM element's event registration APIs, these two methods have a twist. As an example, let's say we wanted to listen to the MediaElement's BufferingProgressChanged event, but we want to stop listening once buffering has exceeded 50%. The following code does work: function onLoad(rootElement) {     var mediaElement = rootElement.findName("_media");     mediaElement.addEventListener("BufferingProgressChanged",                                    "onBufferProgress"); } function onBufferProgress(sender, eventArgs) {           // .. do...

Mice, Usability, and Silverlight

There is no mouse double-click event on UIElements in Silverlight. Some people think this is an odd omission. Silverlight's cousin WPF can fire a double-click event, so why not Silverlight? Even JavaScript can catch double-click events inside a web page (although in true web fashion, the exact behavior depends on the combination of browser version, operating system, and the current phase of the moon – see Jan Wolter's Javascript Madness: Mouse Events for all the gory details). You can still detect a double click using a mouse up event handler and a timestamp - but should you? The omission of...

More on Conditional Compilation in ASP.NET

Phil dug up an old post of mine on conditional compilation, but defining a constant in web.config didn't appear to work for him. I didn't see anything wrong with his approach, so I downloaded the solution and did some spelunking. With this page ... <%@ Page Language="C#"      CompilerOptions="/d:QUUX" %> ...     <div>        <% #if BAZ %>          BAZ in the aspx file.       <% #endif %>       <% #if QUUX %>          QUUX in the aspx file.       <% #endif %>     </div> ... ... and this web.config ... <system.codedom>    <compilers>       <compiler          language="c#;cs;CSharp" extension=".cs"          compilerOptions="/d:BAZ"          type="Microsoft.CSharp.CSharpCodeProvider, System,              Version=2.0.0.0, Culture=neutral,              PublicKeyToken=b77a5c561934e089" />    </compilers> </system.codedom> ... then the page behaves as if only the QUUX is defined. To understand the scenario I added...

Nested Selects in LINQ to SQL

Consider the following diagram to track the votes in a contest. Each voter can register only one vote (a score from 1 to 4) for each contest entry. For any given voter, you'll want to present a screen showing every entry in the competition, along with the score assigned to the entry by the voter (if a score exists). To fetch the data with SQL, I'd write something like: SELECT E.EntryID, E.EntryName, E.EntryDescription, @VoterID AS VoterID,        (SELECT V.Score         FROM   Votes AS V         WHERE (V.VoterID = @VoterID) AND (V.EntryID = E.EntryID)) AS Score FROM Entries AS E The query should yield a resultset like the following: ... EntryID...

10 Tips for Shrink-wrapping ASP.NET Applications

Most server-side applications run on machines under our control. We know what the application's environment will look like long before deployment. Building and packaging an ASP.NET application to deploy inside of any corporate firewall is a bit more challenging. Here are a few lessons I've learned from five years of building a commercial web app. Document your required configuration. Use this document in the sales cycle and again before delivering the software to make sure there are no surprises. Verify the environment. Even though your document says you require SQL 2005 SP2, someone will point your software to a...

Check Back In A Couple Days

I'll blog again as soon as this little operation finishes....