Did you know that? With Visual Studio 2003 we were able to extend the System.Web.UI.Page class and create new properties for WebForms. Test yourself, using VS2003, create a new property for your class (derived from System.Web.UI.Page), create a new ASP .Net page based on your new class and you will see the created property it on the Visual Studio properties page for the ASPX.

When saving the page, you will see that the code behind is automatically changed to include the property values. It is a very easy approach to create custom properties on ASP .Net web pages.

A couple of weeks ago I was working with one of our customers and I said that he could use the properties approach to easily customize the appearance of his ASP .Net web pages. But what’s my surprise when I noticed that this is not working on Visual Studio 2005.

Ok. Know the reason for such thing not work anymore became a question of honor. After post some questions on our internal lists and search a little bit on the Internet I figured out the reason.

Before begin the explanation, I’d like to let you know that it is a known issue reported at http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105510.

Let’s try to explain.

According to my research there was a design change in the product. Basically in Visual Studio 2005 RTM, the code behind file and the generated stub are compiled into the base class, and the actual ASP .Net page inherits the base class.

The V1.X code behind model (seen on the Visual Studio 2003) is still supported by the runtime, however, you cannot use Visual Studio 2005 for editing the V1.X style pages.
 
The code that was being generated by Visual Studio 2003 IDE is now moved to the partial class that is automatically generated during compilation. If you just want to see what is in the generated class, you can set the page to debug mode and look for the generated files under the ASP.NET temporary folder.

The model is changed to allow updatable pages after compilation. To achieve this, the product group came up with the current model which is very similar to V1.X that the codes behind files are still compiled into the base classes. The only difference is that the control field declarations and the class constructor are now automatically generated instead of injected at design time.

So the collateral effect appeared. As the control field declarations are automatically generated at the compilation time we cannot store the adjusted values for custom properties on the appropriate place. Therefore we need a different approach to implement this kind of functionality.

I managed to implement (with the help of a sort of samples) a mechanism that can be used to coordinate the appearance of ASP .Net pages at design time using class properties injected manually on the code. I’ll show how to do that on another post. Stay tuned!

Bye!!

This posting is provided "AS IS" with no warranties, and confers no rights.