Shawn

Shawn Wildermuth

Button.OnClientClick() in ASP.NET 2.0 Rocks...


This new property (*not* event), allows you to wire up clientside code to be executed before the server-side onclick is handled.  In the old days we had to do this manually.  For example, this is how you would hook up a simple confirmation dialog:

<script language="jscript" type="text/jscript">
<!--
  function deleteConfirmation(event)
  {
    if (!window.confirm("Are you sure?"))
    {
      window.event.returnValue = false;
    }
  }
-->
</script>

<asp:LinkButton ID="deleteButton"
                   runat="server"
                   CausesValidation="false"
                   CommandName="Delete"
                   OnClick="deleteButton_Click"
                   OnClientClick="deleteConfirmation()"
                   Text="Delete">
</asp:LinkButton>

This allows you to cancel the server-side event if the user says nope!  Cool!