It took me a while, but I've finally taken big notice of one of the new little features in ASP.NET 2.0.
The gem is the Button.OnClientClick property and it allows you to respond to a user click event with both client side script and server side code.
The typical example of it's use is to pop up an "Are you sure?" alert on the client side prior to doing something like deleting a record on the server side. In the ASP.NET 1.x olden days, I had to put the script for the "Are you sure" function into the "onsubmit" property of the form. So that when the user clicked the server side "DELETE" button, the form would run the Alert before the postback would occur (a false reply would prevent the postback from happening at all.)
Alan Cooper fans, such as RichB who comments on this blog post by Scott Guthrie about OnClientClick, will continue to decry the use of alerts, popups and other exhibitions of developer "cop-outs". Sorry, but I'm really trying to be polite and not roll my eyes about that.
But I actually have found a wonderful use for the OnClientClick event that has nothing to do with popups. In my many ink on the web samples (e.g. this MSDN article on many ways to persist ink data), I have to do some work on the client side and some work on the server side in order to move the ink data to the server. I have had to do this with a complexity of client side components, limitations on forms and controls that can be available on the server side and using HttpHandlers (though I really like HttpHandlers!).
Now with the OnClientClick property, I can allow one ASP:Button to handle both the necessary client-side functionality (extracting the data from the ink control and surfacing it into a server accessible control) and the server side functionality (taking that data and sending it off to a web service or a database) all in one click. I still have some experimenting to do, but I'm hoping that some of the other limitations I found (crazy things like scenarios where I had to remove runat=server from the form) will be relieved now.
Where have you used OnClientClick that would not get your coding labeled as a cop-out?