Most of the primitive types in the CLR have a Parse method that takes a string and parses it into its own data type. I could be DateTime.Parse(string) or Int.Parse(string) etc. It’s a great way of doing late binding and adds another layer of flexibility to your code.

In ASP.NET you can parse strings as controls and add them to the page or GridView or any other control. It basically means that you can late bind the different controls of a page. Imaging having all the different types of controls you want to use in a predefined XML file and then load them dynamically. Then you only have to change the look and feel of them in one place.

In this example I parse a simple <div> tag and give it an ID so that it can be found in the controls collection.

Control div = ParseControl("<div>Some custom control</div>");

div.ID = "div";

Page.Controls.Add(div);

 

// Find the control by its ID

Control control = FindControl("div");

You can also parse server controls, but they don’t need an ID if you add the attribute yourself.

>

ParseControl("<asp:textbox runat=\"Server\" id=\"txtName\" />");

The ParseControl method can be used to create some extraordinary flexible and extendable web applications if it is used correctly. It could easily become difficult to maintain a website with too many dynamically added controls, if it’s not well thought through so be careful.

The Visual Studio 2005 launch improved so many things from older versions – some big and some small. Yet somehow it is always the small things you remember. The 2005 release is superior in almost any aspect except one – it is missing the “Create GUID” menu item. The older versions had it and even though it is not the most widely used feature, it is something I’ve been missing many times.

Even my boss got so annoyed that he built a console application and put it in C:\Windows\System32 in order to access it easily through Start –> Run. Later we learned about this wonderful website www.newguid.com but we already had the console application, so that was a little too late. As you can see, this feature has been greatly missed.

Microsoft realized they were on thin ice by removing the feature, so they made a wise decision in Service Pack 1 for Visual Studio 2005. Can you guess what it is?

They brought it back!

And not only is it back, it is also a little bit better. A GUID is a GUID is a GUID, I know, but somehow it just feels better. I would like to thank Microsoft for putting the feature back in Visual Studio, but that would be like thanking the dry cleaners for returning your pants a year too late.

You can find it in the menu under Tools –> Create GUID, just like in the old times.