July 2005 Entries

Speaking Of Master Pages

If you are in the Batimore / Washington D.C. area, come out to the next CMAP user group meeting on Tuesday (August 2, 2005). I’ll be giving a 20 minute presentation on Master Pages in ASP.NET 2.0 as part of the opening act for Brian Noyes. Brian’s feature presentation is also a 2.0 topic: Present Rich Data Interfaces with the DataGridView Control. User group meetings are a great chance to network, eat free pizza, win prizes, and discuss technology. The setting is comfortable, the screen at the new meeting location is massive, and you won’t leave without learning something. See...

Vista Beta 1 On Virtual PC

I wanted to try the Vista beta on a fresh Virtual PC this evening, but setup doesn’t cooperate. Here is how I worked around it: When you get to the “Install Windows” screen, press Shift+F10 toopen a command prompt. Type DISKPART at the prompt and use the following commands. select disk 0 create partition primary select volume 1 format fs=ntfs label="vista" After this I typedEXIT to leave the utility, reset the VPC, and started the installation again. If everything looks good, I’ll cross my fingers and install on my non-virtual laptop over the weekend.

The Problem with Test Driven Development

Unit testing fanatics might find the content of this post disturbing. I’m going to point out a fundamental problem with the TDD approach, and I’m not one to just point out problems, so I also offer a solution. TDD fanatics often wonder aloud why the weary masses have not thrown off the shackles of hack and slash coding, why they have not come running to the glow of green lights and the feeling of confidence the lights imbue. The merits of TDD are so obvious, the fanatics think, that any software developer should instantly evolve into an enlightened one –...

Adapter Patterns and Cross Page Post Backs

It was a quiet weekend morning, and I thought I’d write up a quick blog posting with the above title. About 1400 words later, I realized I had zoomed past post length material into article length, so I put Design Considerations for Cross Page Post Backs in ASP.NET 2.0 in the main OdeToCode article area. Excerpt: It’s also interesting to note the behavior of the PreviousPage property during a cross page post back. PreviousPage uses lazy evaluation, meaning no previous page will exist until the first time you touch the property. At that point the runtime will load a new...

String Basics Part II

The sample code in this post demonstrates that the run time maintains a string intern pool. The intern pool allows sharing of string instances. Interning is primarily a memory optimization, but can also be a performance optimization in some unique scenarios. The runtime will store strings literals in the intern pool. For example: using System;   class Class1 {     [STAThread]     static void Main(string[] args)     {         string s1 = "bbb";         string s2 = "bbb";         Console.WriteLine("{0},{1}", s1, s2);     } } If you look at the IL code for the above program, you might be tempted to think we are dealing with two different string instances. In...

String Basics Part I

I’ve used the snippet of code at the end of this article twice in the last week to clear up some misunderstandings about strings in .NET. System.String is a reference type in .NET. Don’t let anyone mislead you into thinking otherwise. You’ll hear people saying strings “act like value types”, but this doesn’t mean the runtime makes a copy of the string during assignment operations, and it doesn’t make a copy of a string when passing the string as a parameter. The equality operator and String.Equals method compare the values of two string objects, and you won’t find a property...

Thoughts From The Drive-Thru

I’m was waiting in the drive-thru lane at the bank today when I picked up the June 2005 issue of Dr. Dobb’s Journal from my backseat. Reading an engrossing article in the car is a fun way to meet new people. When the person behind me honks and shouts “Pay attention, moron! Move forward!”, I know what they are really saying is “I am bored and have nothing to read, will you share?”. You’d be surprised at the conversations that ensue. One of the articles covered new features in the Linux 2.6 kernel, including the EXPORT_SYMBOL_GPL() macro for use in...

Master Pages

My latest article: Master Pages In ASP.NET 2.0. Excerpt: The master page implementation outlined above has another consequence to watch for. Since the master page injects it's controls and markup into a page’s Controls array, any relative URLs in the master page markup may break. Remember, the browser will request the web form, not the master page, so all of the URLs will be relative to the web form. When the web form and master page are in different directories, relative URLs may point to the wrong location. To help alleviate relative URL problems, ASP.NET will rebase relative URLs for server-side controls....

VB.NET versus C# Web Forms

There is a subtle difference in the default ASP.NET 2.0 ASPX files for VB and C#. I mention the difference only because C# is traditionally the ‘explicit’ language while VB.NET is the language with late binding features built-in. A new VB.NET web form places AutoEventWireup=”false” in it’s @ Page directive. This means your code is responsible for explicitly wiring up Page events. A new C# web form places AutoEventWireup=”true” in it’s @Page directive. This means the runtime will reflect upon your code to find method names in the form of Page_EventName and attach the methods as event handlers for named event. Why is this? VB.NET’s...

MasterType in ASP.NET 2.0

Here is something nice that comes from the new compilation model in ASP.NET 2.0. Let’s say you add a custom property to a master page code-behind file like so: Partial Class otcMaster Inherits System.Web.UI.MasterPage Public Property FooterText() As String Get Return Footer.Text End Get Set(ByVal value As String) Footer.Text = value ...

Backstage Blogging

This weekend I’m playing in the pit orchestra for a community theater production of Sondheim’s Tony winner “Into The Woods”. The musical is a funny blend of fairy tales into a story of love, lust, and death by angry giant. I enjoy the music and storytelling in this show. My only criticism is the blatant use of a deus ex machina near the end. Some of my favorite quotes:    Cinderella: Opportunity is not a lengthy visitor.     Cinderella’s prince: I was raised to be charming, not sincere.   Rapunzel’s prince: Dwarves are very upsetting.    Jack’s Mother: Children can be very queer about their animals.   Witch: I'm...

Research

I should have grown up to be a researcher. Easy money – no stress. Take this for example: someone made money doing a survey that discovers the vast majority of men at a nude beach don’t object to seeing nude females. Well, duh. As a follow up, the survey team will find out if the majority of people in a steak house restaurant object to seeing medium rare prime rib. Here is another interesting study: IQ Dips More on Email Than Pot. The study claims that distractions from emails and instant messages make people brb Where was I? Oh, right. I...

Moving ASP.NET Apps from IIS 5.x to 6.0

Here are areas to watch when moving an ASP.NET app from Windows 2000 / XP ( IIS 5.x) to Windows Server 2003 (IIS 6.0). These notes assume you do not configure IIS 6.0 to use IIS 5.0 isolation mode.  - Worker Process ChangesWeb applications execute inside a worker process to isolate themselves from IIS. The isolation allows IIS to continue running and servicing requests even when your web application is going down in flames. In IIS 5.x the worker process name is aspnet_wp.exe, and the process runs under the ASPNET account. The ASPNET account is a local machine account and has...

The Monad Experiment

When I saw Adam Barr’s “Monad and RSS” posts (Part I, II, III), I thought of something I’ve wanted to have recently: a utility to parse through my OPML file and tell me what feeds were dead or not updated for months. Monad is the up and coming command line shell in Windows. Adam’s samples made XML in Monad look easy, so I thought I could bang out a quick script… … then I discovered the pain of umpteen different syndication formats, each with their own quirky implementations. I am now amazed there are any working feed readers in existence....

Migrating Base Page Classes Currently Broken

If you derive your web form code-behind pages from a base class to manipulate common controls, your code won’t be happy with beta 2. For instance, deriving a web form from the following class will result in a null reference exception in AppBasePage_Load (commonLabel is null). using System; using System.Web.UI; using System.Web.UI.WebControls;   public class AppBasePage : Page {     protected override void OnInit(EventArgs e)     {         this.Load += new EventHandler(AppBasePage_Load);     }       void AppBasePage_Load(object sender, EventArgs e)     {         commonLabel.Text = "Hello World";     }       protected Label commonLabel; } In 1.x ASP.NET would wire up commonLabel to a server-side control with the same ID. In 2.0 ASP.NET will code-gen...

Book Giveaway Winners

The winners of the first OdeToCode book giveaway are: Steve Wright, Rick Nakroshis, and Hermann Klinke. These three gentleman each won a book from Packt Publishing. Thanks to everyone who entered – we had a great response. If you didn’t win this time, then try again in the next contest...

Configuration & ASP.NET 2.0

My latest article covers interesting features in the .NET 2.0 configuration API. In 2.0 you can not only read from configuration files, but you can write to configuration files, too (even on remote machines). There are permission issues to watch for, and of course any write to a web.config file will cause a web application to restart in a new AppDomain. There is some additional flexibility with both of these issues thanks to the new configSource attribute. The configSource attribute allows you to move a configuration section to an external file. Combining this feature with restartOnExternalChanges=”false” means you can avoid...