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!



Shawn
Shawn Wildermuth
Author, Teacher, and Coach




My Courses

Wilder Minds Training
Vue.js by Example (New Lower Price)
Bootstrap 4 by Example (New Lower Price)
Intro to Font Awesome 5 (Free Course)
Pluralsight
Building an API with ASP.NET Core (New Course)
Building a Web App with ASP.NET Core, MVC6, EF Core, Bootstrap and Angular (updated for 2.2)
Less: Getting Started (New)
Using Visual Studio Code for ASP.NET Core Projects
Implementing ASP.NET Web API

Application Name WilderBlog Environment Name Production
Application Ver v4.0.30319 Runtime Framework x86
App Path D:\home\site\wwwroot\ Runtime Version .NET Core 4.6.27817.01
Operating System Microsoft Windows 10.0.14393 Runtime Arch X86