Practical ASP.NET

My Biggest ASP.NET Programming Mistake

VSM columnist Peter Vogel builds an ASP.NET application that is too clever by half, and finds himself at odds with the very environment he is supposed to be leveraging.

I recognize now that I was being dumb, but at the time I thought I was being damn clever. This was in the days of ASP.NET 1.0/1.1 and I had this brilliant idea for how I could structure an application for one of my clients. Well, it seemed brilliant at the time.

At the time, I was in love with User Controls. And they are a tremendously useful tool when used appropriately. But I decided that it would be cool to build the client's entire site around User Controls.

The site would have exactly one page with two Panels in it. In the rectangular Panel on the left hand side of the site's page, we would load User Controls that held the site's menus. Each menu choice would be represented by a button. When a user clicked a button, I'd load a User Control into the larger, square Panel on the right-hand site of the site's only page. These User Controls would be the site's "pages." To make things more interesting, some of the menu buttons would cause the menu in the left hand panel to be replaced.

I thought this was a brilliant design. I may even have used the word "elegant." The plan was that we would add new pages and menus just by adding new User Controls to the site (I don't remember why I thought this was superior to adding new pages). Now, I could claim that I was fumbling my way towards something like Master Pages, but I'd just be trying to put lipstick on a pig.

But there was more: I had plans for this design. Down the line we would be able to make the site structure table-driven by having a set of tables listing User Controls and menu buttons. The menu User Controls would use that table to decide what buttons to display and, when the buttons were clicked, what to load in the right-hand panel.

With this extension, we could reconfigure our site just by updating this table. I didn't ask what business need would cause us to want to reconfigure our site this way -- the important thing was that we could do it.

It took a lot of futzing with code to get this to work. I have, fortunately, blanked out many of the details. I do remember having to write some code where I checked the "parents of parents of parents" of controls in order to figure out the current state of a page. I arbitrarily cut off this search after seven generations for some reason. That should have been a clue, right there, that I was doing something wrong.

Anyway, the first problem revealed itself early: since there was only one page on the site (with various combinations of User Controls in its panels) users couldn't bookmark anything. This actually wasn't much of a problem but it should have told me something. I was violating the rules, conventions and expectations that users have of the Web environment.

If you're going to build something in an environment, it should exploit the environment, not attempt to defeat it. If I didn't want to use the conventions, I should have used some other technology. Besides, we could have fixed that (I think) by doing something clever with the QueryString.

What can I say? I was young.

It was all the futzing around with code and that "parents of parents of parents" thing that should have tipped me off that I wasn't using the tool (ASP.NET) in a way that its developers intended. And, sure enough, I got my comeuppance when ASP.NET 2.0 came out: The whole thing fell apart. It was impossible to implement this design in ASP.NET 2.0. So it was also now impossible (or, at any rate, hellishly difficult) to migrate my client's site to ASP.NET 2.0 so that we could, for instance, use Master Pages.

Anyway, my client ended up moving to ASP.NET 2.0 by creating a new page for every User Control in the old design and then copying and pasting HTML and code between the two applications. Amazingly, that client stuck with me and we're still doing business. Some people never learn. Fortunately for me.

About the Author

Peter Vogel is a principal in PH&V Information Services, specializing in Web development with expertise in SOA, client-side development, and user interface design. Peter tweets about his VSM columns with the hashtag #vogelarticles. His most recent book ("rtfm*") is on writing effective user manuals, and his blog on language and technical writing can be found at rtfmphvis.blogspot.com.

comments powered by Disqus

Reader Comments:

Sun, Mar 27, 2011 Peter Vogel Canada

Tom: That sounds like an old Yiddish saying--"Too soon, old; Too late, smart."

Tue, Mar 22, 2011 Tom Philo Portland, Oregon

Ah the folly of youth compared to the wiseness of experience. Reading it sounds more like you were designing ahead for ease of maintenance - which is always good - but forgot that with a new method of programming it is subject to change - and thus broke later on and the ugly truth of maintaince made a comeback!Problem is, there is no way around this problem even in the future. Designers will still get burned when things change and thus what was working is now broke,

Thu, Mar 10, 2011 Peter Vogel Canada

Ben I really do appreciate making this look "not so foolish." And I won't deny that user controls were a way to get by without Master Pages--but we had other options (server side includes leaps to mind) that wouldn't have cost my client however many days I spent making this work. Guest makes another good point: Nothing beats knowing everything you can about your development toolset.

Thu, Mar 10, 2011 Guest

Man, you're talking almost exactly like my last project application with one sad detail, mine was .Net 2.0 and looks like the guy didn't new anything of master pages =(

Wed, Mar 9, 2011 Ben Wellington, New Zealand

I cut my teeth supporting an application that sounds very similar (ASP.NET 1.1 w/ user controls instead of pages), and I have the scars to prove it. I actually reckon the limitations of ASP.NET 1.1 are at least partly to blame for making this seem like an attractive option. You mentioned in your column that you can't remember why you thought adding a new user control was better than adding a new page. My guess is that without Master Pages to help you, you're forced to repeat a whole lot of HTML between pages to maintain a consistent look-and-feel. Do this for thousands of pages, and you have a maintenance nightmare on your hands if and when the customer changes their branding. Doing something like you describe just seems like the DRYest approach. I never want to go back to ASP.NET 1.1.

Wed, Mar 9, 2011 Peter Vogel Canada

Marc: I appreciate your vote of confidence but there was no way to implement this solution in ASP.NET 2.0 without some significant rewrites (I suspect that Glen's implementation was smarter than mine). Among other things, my solution required that I reach over to a page that wasn't current and access its data--a feature that went away in ASP.NET 2.0 (PreviousPage is NOT the same thing). Not to mention the issues I created for myself around integrating with MasterPages and Content controls... But you're exactly right about the power of giving users the ability to add/remove stuff from the page. At some point that turns into SharePoint, of course, but (in ASP.NET) the right tool for that is User Controls + WebParts. I did a column waaaaaaay back on a reporting dashboard that leveraged those tools to let users add/remove reports from a "reporting dashboard" page: http://visualstudiomagazine.com/articles/2009/03/11/create-a-reporting-dashboard-with-webpartzones-but-without-webparts.aspx. One of the nice things about that solution was that, when a new report was needed, I just tossed it into the catalog for that page: no changes to menuing or navigation required. That was a great solution!

Tue, Mar 8, 2011 Marc Schluper Beaverton, OR

I disagree too. Imagine you have a catalog of tools and each user can select their own set of tools and put them on the pages of their choice (e.g. a page per task they perform). Then it's great to have a UserControl for each tool and load them dynamically based on configuration data in a database and the page selected. And any programmer can tell you how to use the QueryString to link deeply into an application. Moreover, you CAN do this in ASP.NET 2.0 and later as well. So ... no Peter, this was only dumb because you did something that was not required.

Tue, Mar 8, 2011 Peter Vogel Canada

Whoa! There's no control bashing going on in THIS column (well, maybe in the comments--but I have no control over that). I'm a big ASP.NET fan--I even like the UpdatePanel but, again, only as long as you keep it in its place. But I do, from time to time, suffer from programmer's disease: "If it can be coded it MUST be coded."

Tue, Mar 8, 2011 Glen M Cincinnati, Ohio

I don't totally agree with all the ASP.Net Control bashing going on. Don't get me wrong, I do have dings & bumps from the old days. At least until I figured out User Controls. However, I have a very powerful Control based framework that behaves very well. I spend most of my time focusing on solving the business problems now. Controls are very powerful & flexible objects. I guess I could have made the framework Page based as well. Anyway, my 2 cents.

Tue, Mar 8, 2011 Tom USA

And, the same mistake is repeated over and over and over. Each developer thinks he/she is "all that" and will show everyone else their brilliance. It's good to get that lesson early... takes the cockiness out of new developers. :)

Tue, Mar 8, 2011 Mike D Philadelphia Suburbs

Ahhh, yes. Doing it because we wanted to know if we could. There's such a fine line between breaking the rules (in a bad way) and breaking the rules in a groundbreaking "next best thing" kinda way that we can't beat ourselves up too badly, right? I have been in your shoes as well. We both lived to tell the tales and laugh at ourselves, right?

Tue, Mar 8, 2011 Jasmine jazzyflight.blogspot.com

Sounds like DotNetNuke.

Tue, Mar 8, 2011 Rocky London

Oh yes the "Sweet" memories of when we "knew" we were better than the rest :) It reminds me of "Why use a database when you can write it all to a text file".

Tue, Mar 8, 2011 remi bourgarel Toulouse, France

This reminds we when I thought that UpdatePanel was the best solution ever for an ajax web site ... This technology is so a black box that there is billions of story like that. Powerfull technology but a bit too much.

Add Your Comments Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.