Friday, January 4, 2008

Easy trick to decreasing your page size!

While working on a project with Than Nap, a fellow Slalom consultant, I picked up a simple trick to decreasing your page size.

If you have worked with MasterPages in ASP.NET 2.0, you have no doubt been looking at the source of a page, and seen something like the following....

The naming convention of controls following the hierarchy of pages in which the control is nested. When the ID of a masterpage is not explicitly set, it defaults to ctl00. When you add a new MasterPage to a project/website, you get default content like the following...

If you just start going from here, you may be making a mistake. The names you give (or don't give) your MasterPage and ContentPlaceHolders show up twice per control. And you might be appalled if you look at the source for a gridview/detailsview.

Here's the tip:

  1. Name your contentplaceholders with as short of name as possible. I use "c" for a main content area, "t" for a title, and so on.

  2. Add the following piece of code to code behind of your MasterPage.

The same example I started with (btnSave) would now look like this in source...

In larger applications, with complex web forms, this little trick may get you a 10% decrease in page size alone!


  1. I wish your code wasn't an image so I could copy and paste :)

  2. Yet to discover a good way to post code snippets without them being images :-)