Skip to the content Back to Top

It seems like I just can't find enough gotchas this week. My latest is the use of the ValidationGroup attribute when validating user input in ASP.NET 2.0.

If you use ValidationGroup="Foo" on a validation control, then the postback control (a Submit button, perhaps) must also reference that validation group, or no validation occurs. In hindsight, this is logical and even obvious. Hindsight is always annoyingly obvious. Meanwhilesight, however, had me crossing my eyes in vexation because I couldn't understand why the validation controls simply weren't firing (client-side or server-side).

I had used ValidationGroup on all my validation controls, but had forgotten to reference the group name when I added a button the next day. The .NET can be a harsh mistress.

When using Web Application Project with Visual Studio 2005 instead of Website Project, the profile personalization feature new to ASP.NET 2.0 doesn't "just work" the way all the articles describing Membership and Profile say it does. The strongly-typed ProfileCommon class is not auto-generated and Intellisense tells you it has no idea what you're talking about when you attempt to access HttpContext.Profile from code.

ScottGu reveals (full article):

VS 2005 Web Application Projects don't automatically support generating a strongly-typed Profile class proxy. However, you can use this free download to automatically keep your own proxy class in sync with the profile configuration.

I got quite frustrated, enough to bang the desk, but fortunately not enough to emit a Primal Yodel. As usual, Super Ted came to the rescue and pointed me to the above download.

UPDATE June 25, 2007 - The gotdotnet site in the "free download" link above has shut its doors, possibly forever, so here is a copy of the Web Profile Generator for your downloading pleasure: Web Profile Generator download.

UPDATE II from Ted, July 4, 2007 - As of yesterday, the Web Profile Generator lives again on CodePlex: http://www.codeplex.com/WebProfile

When working on ASP.NET web applications, it's not unusual to be working with the System.Uri class, which is an object representing a uniform resource identifier (URI). It can spit back handy references to various properties of a URL, such as host, query, scheme, yada yada.

I was down in the dingy Andornot lab today, working on the Onesearch class library and feeling clever because I was using Uri objects to hold WebPublisher search URLs instead of mere strings. But strangely, something kept going wrong whenever I called upon the Uri to actually perform a web request. The search text I was passing in was not getting encoded. (This is so "doctor & nurse" gets encoded to "doctor+%26+nurse" and doesn't make WebPublisher cry like a wet-nappied baby.)

I encoded that string every which way I knew how, and viewed the results in the trace log. It was going in encoded, but somehow whenever I asked for the whole Uri as a string to make a web request, it came out "doctor+&+nurse". I was going completely bananas. Had I slipped into some alternate Twilight Zone universe? Was there a bug in the .NET 2.0 framework? Where was my encoding? Double U Tee Eff!

I finally figured it out. I had been asking for Uri.ToString(), which indeed returns a full string representation of the Uri, sans encoding, even if you had forced encoding upon any portion of the Uri previously. Buggrit! Millenium hand and shrimp! I humbly accept my chastisement from the gods, and ask instead for Uri.AbsoluteUri(), which returns a full string with encoding. Amen.

As a postscript, UriBuilder.Query is a trip-up as well. Do not append a string directly to this property! I did, and now I'm sorry.

Don't

uriBuilder.Query += "&QI0=smith";

What does that get you? Two question marks preceding the query instead of one.

Do

uriBuilder.Query = uriBuilder.Query.Substring(1) + "&QI0=smith";

Here's some light beach reading done on our recent holidays (vacation for all you American readers). Yes, I have now more than adequately proven that I am a geek. But at least my wife still loves me.

I grabbed it before heading out of country as it's pretty much the first ASP.NET 2.0 book published for the final VS release - and it's not a dumbed-down overview (although, while it states that it's aimed at intermediate-advanced, it's more accurately beginner-intermediate/advanced). From what I've gone through so far (Reigna keeps me rather busy), it's proven to be a great resource. Great overview of 2.0 while providing non-stupid/non-useless real-world examples. Data access coverage is great: it's a small thing, but it's surprising how many resources neglect to mention the importance of closing your connections - this resource is one of the few that does. All in all, pretty much 1000+ pages with minimal fluff. There is one yucky bit in the second chapter discussing Visual Studio 2005:

One convenient way to organize content in a web page is to place it in the different cells of an HTML table using the table tag...in Visual Studio 2005, life gets easier. To try it, drag a table from the HTML tab of the Toolbox. You'll start with a standard 3x3 table, but you can quickly transform it using editing features that more closely resemble a word processor than a programming tool...With these conveniences, you might never need to resort to a design tool like Dreamweaver.

Ikes! A word processor?!? Noooooo! Good thing the authors know their stuff on everything else. I wish I didn't have to resort to Dreamweaver, but if this is what is lauded as stellar design tool improvements in VS, somebody needs their head checked. Take a look at Dreamweaver 8 (and weep). VS CSS support still, well...let's leave it unsaid. But heh, out of 1000+ pages, only one page that needs to be burned is not bad at all. When I've finished, I'll likely come back and do a better overview (or not). So far, highly recommended.

Ted

Categories

Let Us Help You!

We're Librarians - We Love to Help People