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 system architect and principal in PH&V Information Services. PH&V provides full-stack consulting from UX design through object modeling to database design. Peter tweets about his VSM columns with the hashtag #vogelarticles. His blog posts on user experience design can be found at http://blog.learningtree.com/tag/ui/.

comments powered by Disqus

Featured

  • Mastering Blazor Authentication and Authorization

    At the Visual Studio Live! @ Microsoft HQ developer conference set for August, Rockford Lhotka will explain the ins and outs of authentication across Blazor Server, WebAssembly, and .NET MAUI Hybrid apps, and show how to use identity and claims to customize application behavior through fine-grained authorization.

  • Linear Support Vector Regression from Scratch Using C# with Evolutionary Training

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the linear support vector regression (linear SVR) technique, where the goal is to predict a single numeric value. A linear SVR model uses an unusual error/loss function and cannot be trained using standard simple techniques, and so evolutionary optimization training is used.

  • Low-Code Report Says AI Will Enhance, Not Replace DIY Dev Tools

    Along with replacing software developers and possibly killing humanity, advanced AI is seen by many as a death knell for the do-it-yourself, low-code/no-code tooling industry, but a new report belies that notion.

  • Vibe Coding with Latest Visual Studio Preview

    Microsoft's latest Visual Studio preview facilitates "vibe coding," where developers mainly use GitHub Copilot AI to do all the programming in accordance with spoken or typed instructions.

  • Steve Sanderson Previews AI App Dev: Small Models, Agents and a Blazor Voice Assistant

    Blazor creator Steve Sanderson presented a keynote at the recent NDC London 2025 conference where he previewed the future of .NET application development with smaller AI models and autonomous agents, along with showcasing a new Blazor voice assistant project demonstrating cutting-edge functionality.

Subscribe on YouTube