Showing posts with label particletree. Show all posts
Showing posts with label particletree. Show all posts

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.

Thursday, July 31, 2008

Cool buttons with ASP.NET WebForms

The great guys at Particletree (makers of Wufoo), wrote a great article about really cool ways to style buttons:

Rediscovering the Button Element

If you make web sites, go read that post, it's great!

The cool thing is how both buttons and regular links look exactly the same, for me this means no more buttons with

onclick="window.location.href='foo'"
just regular links that look the way I want them to.

Of course, being a noob is hard, and I wasn't sure how to create '<button>' elements that perform a postback in ASP.NET WebForms, but a little Google searching later HtmlButton comes to the rescue, and that allows me to create these cool buttons and links that look like buttons:

Cancel

And the markup couldn't be simpler:

<div class="buttons">
  <button
      runat="server"
      onserverclick="SaveButton_Click"
      type="submit">
    Save
  </button>
  <a href="#">Cancel</a>
</div>