ASP.NET 2.0, Dropdowns
I’ll keep this as short as possible. I’ve been doing more ASP.NET 2.0 development at work. Sometimes I’m amazed at how simple and fast you can do something. Other times I’m horrified at how lacking it is. I have nothing particularly against ASP.NET 2.0, but if it was something opensource… people would be fixing these petty problems. Here’s an example:
You have a drop down list on a page that is DataBound to a list of items. These items all appear on the page, but you may have to scroll to them. You want to let the use select the item from the drop down and scroll to it (with the magic of anchor tags). Typically you add an “onchange” event to call some javascript that does this. Something simple like: window.location = “#item_id”;
Unfortunately, ASP.NET 2.0 doesn’t want you to do client side scripting with their controls, so you left with these options:
1. Render the control manually in the ASP page. This is the method we’ve been doing for years, creating large unreadable source pages. It’s what all this ASP control jazz is supposed to fix.
2. Extend or rewrite a new control that accepts this property with no complaints. This may already be done by someone out there. Down side is you add a dependency to your project and usually get a bunch of other crap you didn’t want. Extending it consumes some time, but if done write you can probably reuse it.
3. Add the ‘onchange’ attribute to the control with some code: controlName.Attributes.Add(“onChange”,”javascript: return confirm(“Are you sure?”);”); This works, but you end up combining your view and control code, which once again is something ASP was supposed to fix…
None of these solutions are particularly good. When I worked on a site that used Castle I found many similar problems with their “Helpers”. I submitted updates to them, so everyone benefited. With Microsofts ASP.NET, we have to bitch about it. Send in a request. Wait. Wait some more. Then maybe they integrate the requested fix/feature in the next version. The whole process taking years usually.
Note: I’m not endorsing the use of Castle. It’s relatively mature, but doesn’t provide much of an advantage over a well designed asp.net site. Also, to do anything moderately well in ASP.NET, you should understand their DataSource stuff. For larger sites, be prepared to write your own datasource handlers, because the ones they provide are limited in their usefulness on large sets of data (e.g., they retrieve full sets of data before pagination or sorting).