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

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube