ASP.NET OnClientClick Property
Definition and Usage
When the ImageButton control is clicked, the OnClientClick property is used to set the client-side script to run.
In addition to predefined scripts, scripts specified in this property are executed through the ImageButton's "OnClick" event.
Syntax
<asp:ImageButton OnClientClick="func" runat="server" />
Property | Description |
---|---|
func | Client-side script run when the ImageButton is clicked |
Example
The following example runs two scripts when the ImageButton control is clicked:
<script runat="server"> Sub script1(obj As Object, e As ImageClickEventArgs) lblMsg.Text="Hello!" End Sub </script> <form runat="server"> <asp:ImageButton OnClick="script1" OnClientClick="script2()" ImageUrl="img.gif" runat="server" /> <br /> <asp:label id="lblMsg" runat="server" /> </form> <script type="text/javascript"> function script2() { return confirm('Hello!'); } </script>
Example
- Run two scripts with one button