Adding client script to server control in ASP.NET 2.0

Sometime back I wrote an article to display dialog box in ASP.NET 1.1. As I have explained in that article, to pop up a dialog box, you need to add an attribute "onclick" event to the server control. This requires server-side coding even if you want to display a basic client side confirmation message. In ASP.NET 2.0, by adding "OnClientClick" event to the Button control, Microsoft has made this task easier. You just need to place your client-side code in "OnClientClick" event of the control and you are done.

Here is the code snippet to explain that:

<asp:Button ID="buttonAlert" runat="server" Text="Alert" OnClientClick="alert('Button Clicked!');" />

<asp:Button ID="buttonDelete" runat="server" Text="Delete" OnClientClick="if(confirm('Are you sure to delete?')){}else{return false};" />