Monday, August 11, 2008

ASP.NET WebForms buttons and form submission

There's a problem with my previous solution to using Particletree's cool buttons - on IE7 (and only IE7) the click handler gets called twice. It turns out there's a proper way to handle form submission in ASP.NET WebForms - that lets me handle a POST the way I'd expect - and I just wasn't using it.
HTML (aspx):
<form runat="server">
   ...
   <button type="submit">...</button>
</form>
Notice that there's no 'onserverclick'.
Code-behind:
protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        // handle form submission
    }
}
Shame on me for not learning the basics.