The Missing Feature with ASP.NET Forms Found: Default Buttons

In the real world of HTML, you use a separate <form> tag for each form on your page. If I have a currency converter in my travel website’s sidebar, it has its own form tag. As a result, when I press “enter” in a text field, the right submit button is pushed and only that form is submitted.

In ASP.NET we just wrap the whole page in one massive hack of a <form>-esque tag.

<rant>That bit always annoys the hell out of me – but I guess that what’s you get when you let architects try and replicate a windows development model onto the web.</rant>

The most annoying thing however has always been how to map the “enter” effect to the right button. Well, in ASP.NET 2.0 a feature shipped that I never noticed – and it’s pretty cool.

    <asp:Panel DefaultButton="MyButton" runat="server">
        ... my form here ...

It still submits everything to the server, which is a bit wrong, but at least you get the right UI model.

It omits horendous output:

    <div onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ctl00_ContentPlaceHolder_ctl10_ConvertButton')">

…but I guess with a megahack like <form runat="server"> there’s not much you can do besides hack it further.

My excitement about this feature, mixed with the disappointment of <form runat="server"> has left me in the same mood I started in.