I like ASP.NET, I really do, especially with .NET 3.5, C#, with VS2008. It’s fun and rewarding.
But…I have just a few gripes I’d like to mention: inline styles, leaky abstractions, and ID mangling. These are the challenges that I have dealt with so far with ASP.NET.
First: inline styles and stupid HTML. If you’ve done any serious ASP.NET work where you care about the HTML markup, you are already coping with this gripe. ASP.NET controls can be very cool, but they can also generate some stupid HTML come runtime.
For instance, the ValidationSummary. This is a handy control to list all the form errors for your user, and it works great with the built-in validators, which I am a fan of. But have you looked at the markup it generates? You get an inline style with something like color:red;font-style:bold; or something like that. What the…? Why would you presume that I wanted that? It also generates a div around the unordered list of errors. Seriously!? Why not just let me put the div around it if I want to?
Solution: Set ForeColor=”" and the inline styles will go away. You’ll just have to live with the div for now–which isn’t the worst thing ever.
Next: the checkbox list. This is a great control that renders as a freaking table! Why!? Why not just…I don’t know…a LIST OF CHECKBOXES? I’ll admit that I have used this control anyway, because it’s just so darn handy. Alternative solution: repeater full of checkboxes. Annoying.
Here’s a new one for me that sparked this whole blog post: do you know that if you set a checkbox to “Enabled=false” in the code-behind, that it will not only set the checkbox to “disabled” (which is fine), but it will also inexplicably put a span around the checkbox and put an attribute of disabled=”disabled” on the freaking span!? I don’t think that has ever been valid in any iteration of HTML/XHTML. Why, Microsoft, why?
Solution: Step 1: remove brain. Step 2: instead of Checkbox1.Enabled = false;, use Checkbox1.InputAttributes.Add(“disabled”, “disabled”);. Step 3: Replace brain.
Another gripe: ASP.NET controls are basically abstractions of normal HTML inputs, but they can be very leaky. For instance:
asp:TextBox TextMode=”multiline” MaxLength=”20″ runat=”server” /
That is valid ASP.NET code. However, a “multiline textbox” in normal HTML would be a textarea, which has no maxlength property. So…fail. There’s no workaround for this, folks, sorry; you just have to stay on your toes.
A workaround is to use CSS classes instead of ID’s, and just treat those CSS classes like singletons, but now we’re losing some semantics, aren’t we?
I could go on, but enough griping. There is actually a solution to all of the above that doesn’t involve a cheesy workaround, hack, or basically rewriting the controls’ rendering code yourself:
CSS Friendly Control Adapters Go back to ASP Classic or switch to PHP
- ASP.NET MVC!
That’s right, ASP.NET MVC, everyone’s favorite alternative to WebForms. ASP.NET MVC doesn’t have a ViewState, doesn’t mangle ID’s, and you can use plain old HTML controls (or more likely, HTML helper functions) without sacrificing control over your form. You can use jQuery much more easily. You have much more granular control over markup. Er, and I heard there are a few other benefits as well…seperation of concerns and what-not.
I hate onions: the smell, the texture, the flavor. I find the very idea of them being consumed as food offensive. I find everything about them offensive.
For instance, did you know that the chemical responsible for the wretched odor that onions give off is the same chemical as found in the defensive spray that skunks secrete?
That’s right: Thiol. It’s in skunk spray and it’s in onions.
Just think about that next time you bite into an onion. This message brought to you by the Anti-Onion Council.
You may have heard the term “boxing” in reference to C# or .NET programming. What is it, exactly?
In simple terms, it refers to ‘converting’ a value type to a reference type.
Here’s a quick example:
int i = 1; object o = i; // boxing int j = (int) o; // unboxing
Note that this is possible because object is the ultimate base class.
Generally, boxing is something you want to avoid if possible, since it hinders performance if it’s being performed multiple times, and it’s not always obvious when it happens.