ASP.NET base class refined for total control – level 300

In my last post, I wrote about creating an ASP.NET base class that is in complete control of its execution without the possibility of a derived page executing code when it shouldn’t.  With OOP, we can’t guarantee this if we are exposing virtual methods, but what I have done is laid a framework for developing aspx’s on top of this base page.  Some of my base page is below:

        protected Page()


base.Init +=new EventHandler(Page_Init);

base.Load +=new EventHandler(Page_Load);

base.PreRender +=new EventHandler(Page_PreRender);

base.Unload +=new EventHandler(Page_Unload);


public new event EventHandler Init;

protected new virtual void OnInit(EventArgs e)


Trace.Warn(“Begin Base OnInit”);

if(Init != null)

Init(this, e);

Trace.Warn(“End Base OnInit”);


private void Page_Init(object sender, EventArgs e)


Trace.Warn(“Begin Base Init”);


Trace.Warn(“End Base Init”);

Notice that I use the “new” keywork for OnInit as well.  This is so that if the aspx overrides the OnInit method, it still cannot execute code before the base page gets a chance to.  The base page reacts to the Init Event from its parent, executes some code, then calls its OnInit method (which raises this class’s Init event).  The aspx subscribes to its base class’s Init event.  The end developer experience is exactly the same, but what I do in my base class results in complete control of page executiong most of the time.  Most of the time the aspx will override On* methods and execute event handlers. 

ASP.NET base page that controls page executiong – level 300

Have you ever wanted to make an ASP.NET base page that controls execution of any aspx that inherits from it?  Like controlling exactly WHEN the Page_Load logic occurs?  Maybe logging the beginning and ending of the Load method.  I’ve come up with a way to do exactly that.  I’m not claiming that this is a unique idea, but it’s a very slick way to track and control the execution of all derived pages.


1:     protected new event EventHandler Load;

2: private void RaiseLoad(EventArgs e)

3: {

4: if(Load != null)

5: Load(this, e);

6: }

7: private void Page_Load(object sender, System.EventArgs e)

8: {

9: Trace.Warn(“Begin Load”);

10: RaiseLoad(e);

11: Trace.Warn(“End Load”);

12: }

13: Page()

14: {

15: base.Load+=new EventHandler(Page_Load);

16: }

Notice that I’m using the “new” keywork on my event.  This hides the real event and creates another of my own.  This method will trap the Load event from System.Web.UI.Page and then raise a new Load event that it completely controls.  It can do some work before and after this happens.  Now any aspx that derives from this will be executing within this framework.  When it subscribes to the Load event, it will be subscribing this this class’s load event.  You can also do this with the other events of the Control class.

Virtual Server uses VNC – level 200

I have used VPC 2004, and now I have Virtual Server 2005 installed on my second machine, and I have server images set up with all my different environments.  I’m installing Yukon right now.  I found it interesting that vServer 2005 uses the VNC standard for it’s remote server control.  This was a bit of a nuisance since I use RealVNC on the server anyway.  Virtual Server wanted to use port 5900, and RealVNC was already using it.  I configured vServer to use 5901, but apparently there is more than one configuration point because that broke the configuration page.  I ended up having to configure RealVNC to use a different port so vServer could function properly.  I love VPC 2004, and vServer enables me to use virtual PCs on a remote computer, so as long as I have the disk space, I can set up many different server environments.  It’s a great product.  The hard drive files are compatible between VPC and vServer, but the .vmc configuration files are not.   No biggie.  The hard disk file is what matters, so you can take an image on the road with your laptop by using VPC.

Another Content Management System (CMS) – level 200

I’ve noticed that there more content management systems popping up, and they are all written in .Net.  There’s the hugely famous, DotNetNuke, I’ve got one (EZWeb), David Neal has one, and isn’t .Text a CMS in itself?  How long will it be before they all merge, and we have a defacto standard CMS?  One that handles everything you could want?  Right now, CMSs are geared toward a particular nitch.  DNN is geared toward a multi-user portal.  Mine is geared toward managing a n-sized website with multiple users earch owning a part of the site.  DNN has modules, I have plugins.  They are both .Net user controls.  DNN is fully database-driven.  Mine has a web.config switch that can make it fully database-driven, or fully file-driven. 

It makes me wonder if ASP.NET 3.0 will have a CMS project built in that does it all “without a single line of code”. 🙂

With ADO.NET, if the DB schema changes, restart your app – level 200

Wow!  Hard-to-find bugs can really give you insight into how the .Net Framework works.  I recently just battled an elusive bug that turned out to be quite simple.  In a history table, I logged events.  Each event had a description that a user could type in.  Well, I noticed that longer descriptions were being cut off short.  I looked at the database and noticed that my nvarchar(50) field was the culprit.  So I just changed it to nvarchar(4000) to give the users the most flexibility.  I change the corresponding stored proc to mimic the new field length and then went to test the change.  No dice.  It still cut off my description.  What gives?

ADO.NET!!!  I use an ADO.NET command to call my stored procedure.  The description was being truncated in the ADO call.  I restarted the app, and it worked fine.  ADO caches information about sproc parameters, and I had to restart the app for that cache to be recreated with the new length.