Monday, June 30, 2008

When Properties Are Overkill

When you define publicly accessible state for a class, the first thing you proceed to do is define it as properties or accessor-mutator (get-set) methods. In cases where you have to perform checks on the values for code that can be used outside your assembly (or in large teams), properties do make sense because they keep the system sane.

However, if there's a class that is never going to be used by anyone except for the small group of programmers building it or does not have any checks on the input, regular public member variables are enough. If you do implement a property, it's just going to clutter up your code making it look something like this:

private string m_Name;
public string Name {
get {
return m_Name;
Set {
m_Name = value;
//it's a little shorter with C# 3.0 in .NET 3.5

When it should have been like this:

public string Name;

In .NET, accessing a variable and accessing a property have the same syntax, so there's almost no reason why you should have to implement all the the state as public properties when a simple variable will do. If needed, you can simply go back to the declaration and turn it into a property, something that can be easily accomplished using the refactoring features of the IDE.

In the Java world, it's a bit different - you have to write those get and set methods in the event that you decide to implement some more logic later, because you'll end up modifying a lot of code to add the "set" prefix. (Using the IDE to replace ".name" with ".setName" can change some of the string literal too, so you've got to watch out... Unless you're using an IDE that can go over the entire code that can refactor all references to the variable for you... And assuming you have access to that source code with authorization to modify... We need a new version of Java).

Visual Studio VSS Check-in Tip

If you're using Visual Studio to check in files to VSS, the IDE will lock-up when checking in files as it has to check the status of all the files in the solution. Instead, if you know specifically which files were checked out, you can check them in individually.

Another approach is to Right-click the solution and select View Pending Checkins - this opens up a dialog that works asynchronously i.e. it doesn't prevent you from working normally while it finds the list of files to be checked in. To check in the files, click the Check In button on the Pending Checkins dialog.

A dozen ways to set focus to an ASP.NET control

Allowing keyboard navigation and improving the User Experience for users is usually a concern for web developers. Some use Flash frontends while others go the AJAX route but in the end it's the simple things that matter, such as setting the focus to a input element on a form.

Setting the focus on an ASP.NET control is quite simple in ASP.NET and there are at least half a dozen ways to do it.

Through server-side ASP.NET code, you can:
1. Set the DefaultFocus property of the form (you can also do this in the ASPX file for simplicity)
2. Call Control.Focus()
3. Call Page.SetFocus(controlId)

Through JavaScript:
4. Call document.getElementById(control.UniqueID/ClientID).focus(); either through Page.ClientScript.RegisterStartupScript
5. Same as 4, but using the onload javascript event
6. document.FormId.ElementId.focus()

If you just want to handle the onblur event of a control to set the focum on another control, you might also want to look at TabIndex, which sets the order in which the controls change focus on pressing Tab.

Twitter Error Pages

There are two things about Twitter that have been giving it a lot of press lately - lots of downtime and really cool images on their error pages. The one thing that keeps them from getting bad press resulting from downtime is the cool graphic design team. As much as I like their graphics, I really hope this doesn't become a trend - replacing support engineers and developers with graphic designers.

In case you haven't caught on to the Twitter wave yet, here are the error pages:

border-radius not coming to MS IE anytime soon

According to the CSS Compatibility report for Microsoft Internet Explorer browser version 5 to 8 published here, Microsoft doesn't intend to support the border-radius attribute of CSS 3 anytime soon - both Internet Explorer 8 Beta 1 and Internet Explorer 8 RTM will not have support for the property that can save us all from having to download tiny images of curves (not *that* kind of curves!) to created rounded borders.

Firefox supports the border radius, although it needs the "-moz-" prefix.

"Can you download the Internet for me?"

Back in the early days of the Internet, a few newbies who had just bought a computer would say, "Can you download the Internet for me? I'll get you all the floppies you need." :-D

Here's a little joke that the guys at W3Schools put up about them:

Sunday, June 29, 2008

VNC: Connecting on a non-standard port

Did you ever notice how the colon in a URL is used to separate the hostname from the port number? With VNC, the colon is used to indicate the display number, so that seemed kinda weird. To specify the port number, we have to use a double-colon... VNC uses the single-colon prefix for display number and a double-colon prefix for port number. That surely is a departure from standards :-(


jQuery is a JavaScript library to interact with HTML, create simple animation and add AJAX capabilities. It works across browsers (don't most things do today?), and lets you do more with less.

If you're in the web design & development work, you would have heard about it unless you've been living under a rock, figuratively speaking. jQuery was released in January 2006 and is licensed under the GNU GPL and MIT license. In other words, jQuery is open source and available for free!

The library itself is just 97kB and the latest available version is jQuery 1.2.6 (the previously available version is jQuery 1.2.3). You can read more about the changes made in the latest version here:

EDIT: As Rey Bango points out (in his comment on my blog mirror), the jQuery library is just 16kB when Gzipped. Since most modern browsers support GZip compressed content, the web servers (if configured correctly) should send the content in a compressed form.

Funky Error Messages

Being inspired by Twitter's error messages, I decided to write up some error messages myself...

Access Denied - You can't go there, it's too dark and creepy there!

File Not Found - We've searched, but can't find what you're looking for.

Other Error - Our engineers are scratching their heads trying to figure out the problem.

ASP:Button's UseSubmitBehavior

There's a really cool way to extend an ASP.NET button's functionality in JavaScript and that's by getting ASP.NET to render the button as an Input Button control instead of an Input Submit control - this is done by setting the UseSubmitBehavior property to False.

You can call GetPostBackEventReference to get the Javascript to call the onClick event handler for the button if you need it - this is appended to the OnClientClick handler automatically.

A practical usage scenario is when you want to use a custom dialog with a ModalPopupExtender to confirm a certain action... with a regular confirm dialog, you can return a true or false within the OnClientClick but you can't do that with a custom dialog.

LLBLGen's LINQ emulation with Operator Overloading

LLBLGen Pro uses operator overloading for a really cool purpose - to emulate LINQ in .NET 2.0 when it comes to specifying predicates.

With LLBLGen Pro, you can specify predicates for filtering data within the database, which isn't the same as retrieving all the data to the application server and filtering it with a DataSet.

Most projects today are still based on .NET 2.0 because management is too skeptical about the benefits versus the costs of moving to .NET 3.5. That's where LLBLGen Pro helps make up for the loss of features such as DLINQ.

LLBLGen Pro is a really good Data Abstraction Layer and doesn't force you to use it for parts of the system that you don't want to - you don't run into those caching issues where the ORM tries to do everything automagically. If you want to use a cache, you can implement your own solution and that's low coupling... to do that with a caching ORM, each time you make a direct change to the database that the ORM isn't aware of, you'll end up clearing all of the cache.

Saturday, June 28, 2008

Compressed Stream: GZipStream

With an increasing number of users for an application, an increase in bandwidth usage translates into increased costs for network connectivity. To reduce these costs, it is possible to compress some of the data being sent across. In ASP.NET, you can compress data that you write to a stream using the GZipStream and the DeflateStream classes. These classes are, from a develoepr's perspective, simply wrappers over the actual stream classes. You can use the Read and the Write methods to retrieve and store the data.

The difference between the GZipStream and DeflateStream classes is the GZip header added by the GZipStream - you can open a file written to by the GZipStream using a GZip decompression utility (WinRAR if you're on Windows, GUnZip if you're on *nix).

FileStream fs = File.Open("testfile1.gz", FileMode.OpenOrCreate, FileAccess.Write);
GZipStream gz = new GZipStream(fs, CompressionMode.Compress);
string txt = "Famous last words";
byte[] byteArr = System.Text.ASCIIEncoding.ASCII.GetBytes(txt);
gz.Write(byteArr, 0, byteArr.Length);

ASP.NET Control Adapters

Control Adapters are used to change the HTML rendered by specific ASP.NET controls. You can use them to deliver different HTML to a specific browser. You can also find CSS friendly control adapters on the ASP.NET site at

To create a control adapter, create a class that extends the WebControlAdapter class and overrides the Render method. Then, register the control adapter with the control that you would like to render by creating a .browser file in the App_Browsers ASP.NET folder.

In this article, I'll walk you through an example of a control adapter.

Let's start off by writing the web adapter class to render a Label control by displaying text in italics instead of rendering it within a span tag. The code for this is the following:

namespace ReddyveLib
public class LakeAdapter : WebControlAdapter
protected override void Render(System.Web.UI.HtmlTextWriter writer)
Label lbl = this.Control as Label;
if (lbl != null)
writer.Write("{0}", lbl.Text);

You can then create the App_Browsers folder and create a browser file containing the following XML:

<browser refID="Mozilla">
<adapter controlType="System.Web.UI.WebControls.Label" adapterType="ReddyveLib.LakeAdapter" />

Within the controlAdapters section, we've added an adapter tag that identified the control we want to change the rendering of in the controlType attribute and the adapter class that we want to use in the adapterType attribute.

You can now run the website with a page containing a label and watch the difference.

Friday, June 27, 2008

Visual Studio 2008 Head Content Placeholder

In Visual Studio 2008, the IDE now adds a content placeholder in the header of the master page document by default.

In Visual Studio 2005, the IDE would only add the content placeholder within the form tag in the document body and would display the squiggly underline if you tried to add one into the header although it would still compile and run perfectly well.

ASP.NET Wiki is Down

The ASP.NET Wiki is down today. It just displays a big Service Unavailable message with an HTTP Error 503.

If you've been running 32-bit and 64-bit assemblies on IIS and get the Service Unavailable 503 message on your server, David Wang has a blog entry about it here.

Thursday, June 26, 2008

Rounded corners in CSS3

Getting rounded corners in CSS3 would be as simple as setting the border-radius attribute.

Mozilla Firefox and WebKit-based browsers support the border radius, although with a non-standard attribute names: -moz-border-radius and -webkit-border-radius (yes, with the leading hyphen)

I've tried it on Firefox 3 and find the anti-aliasing to be a bit too fuzzy. Internet Explorer 7 doesn't support it yet though. Opera 9.5 doesn't seem to support it either.

There are a lot of other cool effects provided by CSS3, such as the nth child pseudoclass that allows you to, for example, provide styles for alternating rows in a list. The CSS looks a little like this:

li:nth-child(2n) { background-color: #6f6; }
li:nth-child(2n):hover { background-color: #090; }

It makes me wonder... if they had a 2n and a 3n, which would be applied on the 6th element? :-P I guess that would be browser specific behavior.

RoundedCornersExtender causes focus loss

We recently had a developer on-board our project team who used every control he possibly could from the AJAX Control Toolkit. It was kinda cool but there were a couple of bugs that came along on a piggy-back ride with some of the controls.

This week, we just realised some of the pages had textboxes that didn't have focus by default. After a 3 hour effort, we realised it was due to the rounded corner extender that we applied on the panels. Getting rid of the rounded corner extender got the page working again. What we found odd is that when the page loads, the onfocus event of the textbox fires but when focus is lost on loading the rounded corner extender, the onblur event did not fire!

Anyway, I guess I'll stick to manually creating rounded corners for now.

RoundedCornersExtender may cause missing borders

RoundedCornersExtender may cause missing borders

If you've been encountering missing borders when using the RoundedCornersExtender, it may be because the panel you're applying the RoundedCornersExtender to may be enclosed within a container that is unable to provide the space for the border to appear. Simply add padding via the CSS attribute to the container for the border to appear.

Example (before):

      <asp:Panel ID="myPanel1" runat="server">
      <ajaxToolkit:RoundedCornersExtender ID="rceMyPanel1" runat="server" TargetControlID="myPanel1">

Example (after):

    <td style="padding: 4px;">
      <asp:Panel ID="myPanel1" runat="server">
      <ajaxToolkit:RoundedCornersExtender ID="rceMyPanel1" runat="server" TargetControlID="myPanel1">

Win XP SP3 needs SP1 or SP2

I got an old laptop back from the dead by installing Windows XP on it. It had a corrupt filesystem so pretty much nothing on it was usable. After getting Windows XP (no Service Packs) running from the restore/recovery disks, I got the setup of Windows XP Service Pack 3 and tried installing it. The setup complained with the error message indicating that it needed at least Service Pack 1 installed. Now, I didn't have Service Pack 1 or Service Pack 2 around because all my computers have restore/recovery CDs that already have SP2 so I got a copy off the Internet. I decided to leave the SP3 installation to another day as I was getting late to work, but was wondering - aren't service packs supposed to be cumulative?

Wednesday, June 25, 2008

Pirate Speak

Hi-ho! I have just found a service to translate English into scurvy pirate lin'o. It be at . It can message directly to twittArrr, PirateSpace or email too.

Errr... what I meant to say is:

Hi! I have just found a service to translate English into Pirate lingo. It is at . It can post directly to twitter, myspace or email too.

Firefox 3 for an IE Developer

If you've been targeting your applications at MS Internet Explorer, you've probably been getting requests to support Firefore 3 since it's got over 8 million downloads (which hopefully translates into 8 million users) worldwide.

When starting off with web development for Firefox 3, you'll probably want to get the Firebug and Web Developer add-ons. They have a different feature set than the Internet Explorer Web Development toolbar so you'll probably have moments of doh-I-had-it-in-IE or cool!-IE-didnt-have-this.

A couple of commonly reported issues by web developers moving from IE to FF3 are:
(i) the inability to resize the file input form control
(ii) the use of the textContent instead of the innerText property.
(iii) use of document.getElementById instead of directly referencing the element by it's ID
(iv) really frustrated IE web developers cursing the web standards

Emailed Document Blocked

I've known GMail to block executable files as attachments so I sent across a help file to a co-worker with a Hotmail account.

I haven't used Hotmail in a while so I'm not aware of the latest 'upgrades' that they provide but they've decided to incorporate a few GMail-like (or Outlook-like) blocking features too. Now, blocking an executable is understandable, but a simple CHM help file is blocked too. To an end user, a CHM file is just another document - it is comparable to an MS Word document or Adobe PDF.

It gets a bit annoying when you expect something to work and it doesn't. I wonder if the paid service from Hotmail is any better. I know for certain that MS Outlook isn't a hot favorite because it blocks attachments, but there are ways around that. To unblock attachments in Outlook 2007, go to the registry key HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Security\Level1Remove and add in the extensions that you want to unblock (in semicolon-separated-value format).

Tuesday, June 24, 2008

Refactoring: Assignment Reversal

If you've been creating ASP.NET web applications long enough, you'll find that the most repetitive tasks are creating form fields based on database tables, adding validators and their associated callout extenders, and assigning values to controls in the Page_Load method and assigning them back to the objects in the event handlers.

The one feature I've been hoping to see in Visual Studio is the ability to refactor code by inverting assignments i.e. turning a = b into b = a, so I can copy across most of the code from Page_Load into the event handler. I wonder if there's any Visual Studio Add-In that does this, preferably something open source. I believe I've seen it in some IDE before... I'm not sure, but I think it was Borland JBuilder.

Monday, June 23, 2008

Nero Scout takes over the computer

I had a process called NMIndexStoreSvr.exe that took up 180MB of memory on my computer, bringing it to a screeching halt. It was Nero Scout looking around for media on the computer. I killed the process and disabled Nero Scout. That should teach those baddies that try to take over my computer :-)

'Symlinks' in Windows

If you're a fan of symbolic links in *nix, you'll probably be excited to know that we've got them in the Windows world too (and they're called NTFS junction points). The reason most people haven't heard of them yet is because the Windows installation doesn't include the tools to work with them - you have to acquire them either as a Resource Kit or by downloading SysInternals Junction.

For most people, Windows shortcuts are good enough since you can just click on them and they mimic the behavior of the file that they point to. However, if you're writing a script file or have a reference to a library through your project, short cuts aren't of much help - short cuts are more of a GUI thing.

If you haven't bought a copy of the Windows Resource Kit, you can use SysInternals Junction, which is a free utility created by Mark Russinovich. You can download it from:

If you've got the resource kit, you can use the Linkd.exe and Delrp.exe utilities to create and remove the symlinks.

Microsoft Buggy Studio 2008

Microsoft Visual Studio is a really buggy IDE for ASP.NET development and it gets annoying at some point. A co-worker at the office has dubbed it 'Microsoft Buggy Studio'. I've seriously thought about switching to Java development where we have the likes of NetBeans and Borland JBuilder. What keeps me from doing that? Getting a job as a Java developer is 'mission impossible' in a city where pretty much all software development is based on Microsoft .NET or uses something like Oracle Forms.

Mars Pathfinder

The most popular robot that made it on another planet was the Mars Pathfinder. It's pretty much something that you would see at a science fair with a few modifications to meet environmental constraints.

The Mars Pathfinder used the VxWorks Operating System. The hardware was a IBM 6000 RISC processor with 128MB RAM. The software was written in C and Assembly Language using the XLC compiler from IBM.

You can get more information about the physical characteristics of the Mars Pathfinder at:

Edit-and-Continue For Web Application Projects

Just in case you didn't know, Visual Studio has Edit-and-Continue support for Web Application projects too. Go to the web application project properties, click the Web tab and check the Enable Edit and Continue checkbox.

Have you ever wondered why Microsoft doesn't leave the Edit-and-Continue option for Web Application Projects enabled by default?

Sunday, June 22, 2008

Fun with Illustrator

Adobe Illustrator can do wonders with photographs by combining 'effects' (called 'filters' in Adobe Photoshop) with the LiveTrace feature to create stunning vector graphics. Check out this pic:

OpenSuSe 11 installer looks like the Vista installer

Every other day, something springs up in the Linux world that looks very similar to something Microsoft cooks up. Check out the OpenSuSe 11 installer above that reminds you of the Windows Vista installer. Isn't that particular bout of 'inspiration' also referred to as stealing intellectual property?

Saturday, June 21, 2008

Using the HttpListener class

Since Windows XP Service Pack 2, there's been a buddy living in the system called Http.sys. IIS and SQL Server both interact with this kernel-mode HTTP listener to receive and response to HTTP requests.

Within the .NET framework, you can build your own application to interact with HTTP requests using the HttpListener class, which is simply managed code built over the Http.sys API.

The code to work with the HttpListener class is quite simple, as illustrated with this example:

System.Net.HttpListener newHttpListener = new System.Net.HttpListener();

System.Net.HttpListenerContext context = newHttpListener.GetContext();
byte[] byteArr = System.Text.ASCIIEncoding.ASCII.GetBytes("Hello World!");
context.Response.OutputStream.Write(byteArr, 0, byteArr.Length);


After instantiation of the HttpListener, we specify the prefix with which we want to receive requests. To process requests originating locally, you can specify a URL with localhost. To receive all requests, you can instead use an asterisk (*). The port number can be specified if you want to listen to requests on a non-standard port (the standard port is 80). The application starts listening for requests on calling GetContent, which is a synchronous blocking method (you can use the asynchronous method instead, if that's what you need). We then examing the incoming request - I left out this step for simplicity - and send out the response by writing to the output stream of the Response object.

With the HttpListener class, handling HTTP requests independent of IIS is a no-brainer. You don't have to work with sockets or process HTTP protocol messages - all that heavy lifting is already done for you by the HttpListener class leaving you to focus on what really matters, the idea that will build a better tomorrow.


I just came across an extension to Transport Tycoon Deluxe called OpenTTD - it adds multiplayer support (beyond 2 players that the original has) and you can play on the Internet servers too. It's like the Multi Theft Auto equivalent for Transport Tycoon.

You can get it from the official OpenTTD site at:

Wednesday, June 18, 2008

Firefox Record At 8m Downloads

Firefox 3 has had over 8 million downloads. You can get the statistics by geographic location on the Firefox site at:

Examining the StringBuilder Class

I don't know what it was, perhaps sheer boredom or perhaps the desire to explore, but I set out to examine the StringBuilder in .NET today. A StringBuilder is used when you need performance with modifying strings within your application. The performance comes from the dynamic extension of the string, rather than creating a new string object each time a modification is made. This behavior is due to immutable nature of the .NET string.

Running a performance test to compare the string class with the StringBuilder class gives the following results:

For 100,000 iterations of appending strings:
StringBuilder: 16 ms
String: 16,000 ms

For 110,000 iterations of appending strings:
StringBuilder: 16 ms
String: 19,640 ms

For 150,000 iterations of appending strings:
StringBuilder: 16 ms
String: 37,953 ms

For 180,000 iterations of appending strings:
StringBuilder: 16 ms
String: 55,687 ms

For 200,000 iterations of appending strings:
StringBuilder: 32 ms
String: 69,047 ms

The time required for appending strings using the .NET String class increases for an increasing number of iterations. However, the time for the StringBuilder class seems to remain constant for a certain range of iterations and then increases for the next range.

The behavior of the StringBuilder results from allocation of memory in a chunk, rather than allocation of additional memory for each append operation. A closer look at the source code of the StringBuilder using the Lutz Roeder Reflector gives an insight into how memory is allocated. Take a look at the following code:

int capacity = currentString.Capacity * 2;
if (capacity < requiredLength)
capacity = requiredLength;
if (capacity > maxCapacity)
capacity = maxCapacity;

A StringBuilder is usually extended to twice it's size. If this length is insufficient, it extends to the required size. However, it does not exceed the maximum capacity specified for the StringBuilder. This approach seems to work fine - the number of memory allocations reduce over time when a fixed-length string is appended to the string builder.

RDP Problems with XP SP3?

Some users on the network have reported problems with Remote Desktop after installing Windows XP Service Pack 3. I couldn't get too many details since I'm in the software development division and the problems are reported to the technical support division and a rollback was already performed for the affected users. My Remote Desktop seems to be working just fine. In fact, I've also got the username and saved credentials information from the SP3 version as seen in this screenshot:

Has anyone else had problems with Remote Desktop after installing Windows XP Service Pack 3? Any idea what they are related to and how to resolve them?

EDIT: XP SP3 causes a problem with accessing remote desktop through Internet Explorer as the ActiveX control gets disabled. To get around this, you can Enable the Add-On "Terminal Services ActiveX control" in Internet Explorer 7 - if you are unable to see this add-on listed, you have to delete the following registry keys:

If you're trying to enable concurrent remote desktop connections to Windows XP SP3, see the article here.

Firefox 3 Download Day Update #2

The download count for Firefox 3 is at 5.4 million. With about 9 hours to go, it could go above 7 million - that's 7 million users for Firefox 3 on the day of the release!

The count for India, which was around 24,000 five hours ago is now at 47,602. UAE was at 1,401 and is now at 3,659. The U.S. was at 1.1 million and is now at 2.1 million.

A few users were unable to download Firefox 3 off the official site - they aren't included in the count unless they get it from the Mozilla servers.

The guys at Microsoft would probably be watching those numbers. It's not very likely for Internet Explorer 8 to get so many takers in one day unless they work on something big on the marketing front.

Firefox 3 Download Day Update

The Firefox 3 download count just went over 3.7 million. When I checked the number of downloads in the United Arab Emirates (west of India, sharing a border with Oman and Saudi Arabia) at 8:15am this morning, the count was at 1401 and right now at 9:15am the count is at 1913 - that's 512 downloads in one hour!

I started a download too this morning, but I got just 5MB of the setup and so got a corrupted file. I wonder if it would double-count if I downloaded again.

Tuesday, June 17, 2008

'Target-less' ModalPopupExtender

When using the ModalPopupExtender in the AJAX Control Toolkit, you have to set the TargetControlID to a control that will be used to open the popup, such as a link or a button.

To open the popups only through code, you can create a dummy panel and assign it's ID to the ModalPopupExtender. Make sure you don't set the Visible property to false - if you want to prevent the dummy panel from affecting the layout, set the style property to "display: none;" instead.

Monday, June 16, 2008

Microsoft Velocity

Microsoft has recently released the CTP (Community Technology Preview) version of their in-memory caching server called Velocity. It's an alternative to 3rd party solutions such as MemCache and Tangosol/Oracle TimesTen that do a pretty good job of storing data within the RAM of multiple servers, effectively speeding up data retrieval for similar queries if used correctly.

The Velocity server is a pretty small download at under 3MB so it wouldn't hurt to try it out, even if you're on a slow link.

The source code to use Velocity looks a little like this:

CacheFactory myCacheFactory = new CacheFactory();
Cache myDefaultCache = myCacheFactory.GetCache("default");
myDefaultCache.Add("key1", "value1");
string retrieved = myDefaultCache.Get("key1") as string;

There's more source code available for using cache regions, but you don't really need it to get started.

Sunday, June 15, 2008

Open XML 1.0 SDK Available

The Open XML 1.0 SDK has been made available by Microsoft on its website

The version of Open XML supported by the SDK is not the ISO-ratified standard, but is instead the version of Open XML used by MS Office 2007. The newer version of Open XML will only be supported in the next version of MS Office due to the work involved in dealing with backward compatibility issues. However, the service pack for MS Office 2007, due in 2009H1, will add support for the ODF (Open Document Format used by Open Office), enabling users to use documents created with the open-source OpenOffice or StarOffice.

More details on the Open XML SDK 1.0 are available here:

Westinghouse in favor of universal power adapter

Westinghouse has just announced last week that they would be building a universal power adapter called the Green Plug to enable all of your devices of the future to draw DC electricity through a single adapter. The aim is to create an adapter that won't end up in the landfill along with the obsolete gadgets.

It's not likely for them to get support from a lot of electronics manufacturers because many of them earn additional revenue from the sale of adapters as spares. HP sells it's adapters for notebook PCs at roughly $80 a piece and that's pretty much the norm among notebook PC vendors.

Saturday, June 14, 2008

2008 Underhanded C Contest

The 2008 Underhanded C Contest has officially begun earlier this week. This year, the contest is about writing code that performs redaction, but fiendishly leaves the redacted data recoverable to some extent.

You can find more on the official website at:

Google's Favicon is Only Experimental

There's an article on the official google blog that states the favicon that Google has set currently is just a part of their design process and isn't final.

The reason for the change in the favicon is to develop a scalable icon that works over the iPhone platform as well as other mobile platforms.

You can see some of the favicons that they went through on their blog article here:

Wednesday, June 11, 2008

Firefox 3 Gets 1 Million Download Pledges

As of yesterday, Mozilla Firefox 3 has 1 million pledges for download. The aim is to set a record of 1.6 million downloads on Download Day.

Check out the screencast demonstrating Firefox 3 features at:

New tutorials on Master pages

Two new tutorials, from Scott Mitchell, on ASP.NET masterpages are now available at

Tuesday, June 10, 2008

Multiple Returns in a Method

I read an article today on the usage of multiple return statements in methods (for the uninitiated, it's about best practices in writing source code) by Remi Sabourin.

A commonly encountered scenario that I can think of with multiple exit points for a method is in map values. Example:

public string GetStringForCode(int aCode) {
switch (aCode) {
case 1:
return "Operation Successful";
case 2:
return "An error occurred";
throw new Exception("Invalid input");

You would probably say that there's nothing wrong with the method above and it executes perfectly fine, and I agree with you there. Given the right input, it returns the desired input. However, it's not very elegant in terms of coding style (think along the lines of having to add a suffix, such as a period, to all of the strings when we've got a dozen cases to handle) and perhaps would make the code a little harder to comprehend for the green. If you ask me, I'd change the same code to:

public string GetStringForCode(int aCode) {
String retVal;

switch (aCode) {
case 1:
retVal = "Operation Successful";
case 2:
retVal = "An error occurred";
throw new Exception("Invalid input");

return retVal;

The above can then be easily modified to:

public string GetStringForCode(int aCode) {
String retVal;

switch (aCode) {
case 1:
retVal = "Operation Successful";
case 2:
retVal = "An error occurred";
throw new Exception("Invalid input");

retVal += ".";

return retVal;

I'm not insisting that we change the tons of old code to make it more maintainable - that wouldn't be very cost effective and may break what already works well. I'm simply suggesting that we be a little more considerate to the developers who would have to work with our code in future, when writing new code.

For more, check out the original article (and the try-finally tip at the bottom of the article) at:

Monday, June 9, 2008

Info on New Thinkpads Is Out

Information on the new Lenovo Thinkpads is out. Changes include naming conventions - in the X series, 12" screen models will be numbered X200s, 13" screen models will be numbered X300s and so on. The new models feature the Centrino 2 processors and DDR3 RAM.

You can download all of the slides at:

Server.Transfer and the Changing URL

When you use Server.Transfer to move the user from, let's say, Page A to Page B, the URL bar still displays Page A because the client browser makes a request to the server for Page A and gets a response. This is unlike Response.Redirect where the client browser is suggested a different URL and it starts a new request. Think of it as an RSS news aggregator site that goes to other servers to fetch content and your client browser only sees the URL of the RSs news aggregator site (although it is a slightly different concept).

Now that we're on Page B (with the URL bar still showing Page A), you can click a button (or anything similar, for that matter) that has a click event handler to perform a Server.Transfer to a Page C. Now, you will notice that the address bar shows the URL for Page B. The reason for this change is that Page B (while accessed through the URL of Page A), caused a postback that was to Page B (with the URL of Page B). The client browser now requests Page B, and therefore displays the URL of Page B in the address bar, and gets Page C as the response from the server.

It's one of those things most developers would not expect unless they've tried it, discussed it or read about it, which is why you find this article up here to create an awareness of this behavior in ASP.NET.

VS2008 Setup Project Target Framework Setting

When you create a project in Visual Studio 2008 targeting the .NET 2.0 platform, you would expect Visual Studio to take care of the rest to enable you to install on any system running the .NET Framework 2.0, right?

Well, apparently not (at least in some versions of VS2008). When you create the setup project for your solution, you need to set the target version of .NET again. Navigate to the detected dependencies, open the Microsoft .NET Framework dependency and go to the properties window for the .NET Fframework launch condition to set the .NET version that you are targeting.

Targeting .NET 2.0 from VS 2008

It's often the last mile in software that cause the most headache.

For a more screenshots guiding you along the way, in case you get lost, go to:

Eye-Fi SD Card

The Eye-Fi SD card looks and feels like a regular SD card but within, it's got an 802.11b WiFi interface. It can send images or videos from a camera to a PC or an online hosting service, thus eliminating the need to carry along your notebook PC, USB cables and other dongles.

On the inside of an Eye-Fi card is Samsung Flash chip and an Atheros WiFi chip. You can see a pretty details snapshot of it on IkonTools:

In a recent incident, a stolen camera had a picture of the felon sent via WiFi along with other vacation pictures. You can read more about the incident here:

SQL Server 2008 Logo

Microsoft SQL Server 2008 now has a logo that represents a dynamic grid. It was launched at TechEd last week and is part of a new marketing strategy by Microsoft. You can find more details about it here:

Sunday, June 8, 2008

Don't Change Google

I came across an article recently by Jeff Atwood about getting rid of the I'm Feeling Lucky button from the Google home page search interface. I actually think it's quite cute. All these years and Google still would look incomplete without it.

It's one of the aspects of branding. Once you get accustomed to seeing a brand with that look, you just wouldn't have it any other way. The new Google favicon (for those of you who have noticed it) is a blue 'g' and that is so not Google-like. It looks like a cheap imitation. A fake. A phishing site.

If you would like to read Jeff Atwood's article, check it out at:

Thursday, June 5, 2008

Readonly Textbox Ignores Javascript Input

When using a textbox with a calender extender, you may want to prevent the user from entering any text. Setting the textbox to disabled prevents the browser from processing events on it too.

The other option is to set the ReadOnly property on the textbox. However, when the textbox is clicked and a value is populated using the calendar extender, a postback doesn't process the value of the textbox because for ASP.NET, a readonly textbox is just that - it's readonly and the value does not need to be processed.

Now, for our purposes, having an editable textbox adds to the burden of validation so what we can do is set the textbox to readonly by setting the attribute on the textbox like so:

TextBox1.Attributes.Add("readonly", "readonly");

This approach keeps ASP.NET processing the value of the textbox on postback and keeps the validation to a minimum by preventing the user from entering any 'junk' data.

Wednesday, June 4, 2008

New video tutorials for AJAX Control Toolkit

There are 46 new video tutorials on using the AJAX Control Toolkit. Check them out on the official ASP.NET site at:

ASP.NET Exception on Age of Empires 3 Site

The pros make mistakes too. Check out the screen capture of the ASP.NET exception thrown by the Age of Empires III site.


Tuesday, June 3, 2008

Client-side Custom Validators

When using custom validators in ASP.NET, you'll probably notice that all of the validation occurs only on postback. This is because the only code present is on the server-side. You can write up your own Javascript function to perform client-side validation and assign it to the ClientValidationFunction property of the custom validator.

The validation function has to use the signature function ClientsideValidationScript(source, args).
You would have to set the IsValid member of the args parameter to true or false, depending on the result of the check condition.


function Scriptology(source, args)
var x = document.getElementById('txtNitin').value;
if (x > 5)
args.IsValid = true;
args.IsValid = false;

Regex or Simple Code

I've seen a solution with an ASP.NET textbox to hold a date value, which was validated by a regular expression validator. The regular expression sure looked ugly with a 2-line long regular expression string.

I compared it with my solution, involving the user of a custom validation, that looks sweet and simple and is easy to maintain. I just used the DateTime.TryParse to set the IsValid property of the ServerValidateEventArgs argument.

Score one for the simple code!

Monday, June 2, 2008

Upgrade from VSS to TFS

It gets so annoying when someone checks in code into the source control that doesn't compile, don't you agree?

Unfortunately VSS doesn't have support processing of rules on check-in and doesn't force users to add a change log entry either. What? No email notification either? This sucks.

That's where TFS comes in... it has a bunch of additional features and is Microsoft's answer to open-source solutions such as CVS and SVN. For more on TFS, there's a page on MSDN comparing the features of TFS and VSS here:

Sunday, June 1, 2008

Illustrator LiveTrace

Adobe Illustrator has this really cool feature called LiveTrace that can convert a raster image into a vector image. Here's a sample that I was able to come up with in under 5 minutes.

After turning the picture into a vector image, I took away the background and changed the colors of a few shapes... all this took under 5 minutes, though a lot of the time was spend looking around for tools in the toolbars since the new Illustrator moved around the tools.

ASP.NET ResolveUrl vs ResolveClientUrl

ASP.NET contains two methods in the Control class that can be used to resolve the "~" to the application root. The ResolveUrl method returns the path relative to the application root, whereas the ResolveClientUrl method returns the path relative to the current folder. Either works fine in most cases.

Migrating an ASP.NET Web Site to a Web Application project

Migrating an ASP.NET web site to a web application project is a relatively simple process.

You can start off by installing Visual Studio 2005 SP1, if you're running VS2005, which is the preferred method or you can just install the extension to Visual Studio that adds the Web Application project support - This should be present by default in Visual Studio 2008.

Then, create the web application project in Visual Studio and copy across all the files from your Web Site project.

You will now probably notice that you have to convert all the CodeFile attributes to CodeBehind attributes and are missing the designer.cs file for all the pages and controls. You don't have to do any of this manually but rather have to use the IDE... Choose "Convert to Web Application" from the context menu of the web application project (in Solution Explorer). This causes Visual Studio to go through all your files, adding the designer.cs file and replacing the CodeFile attribute with the CodeBehind attribute (?).

It should be pretty much all that you need to complete the migration for the average ASP.NET web site project, but in case there's any more work needed, you ought to take a look at this article:

Default namespaces for web site pages

The ASP.NET pages that you create when using the ASP.NET Web Site model for development do not have a namespace and so belong to the global namespace. You might want to add the namespace in manually for consistency with other pages that you create.

The Visual Studio IDE makes this simple by selecting the class, and using the Surround With > Namespace item in the context menu.

Rambling: This is my first post of this month and this blog is now one month old if you calculate by the calendar month and ignore the dates. I guess that calculation would make a baby born on the 31st of December a year older on the next day, if you go by the year and ignore the month and date.