Latest web development tutorials

ASP.NET Button OnClientClick property

Button controls Button controls

Definition and Usage

OnClientClick property is used to set the running for some client-side script when the Button control is clicked.

In addition to predefined scripts, scripts that run attribute specified by the "OnClick" event of the button.

grammar

<asp:Button OnClientClick="function" runat="server" />

属性 描述
OnClientClick 当按钮被点击时运行的客户端脚本。


Examples

Examples

The following examples run two scripts Button control is clicked:

<script runat="server">
Sub script1(obj As Object, e As EventArgs)
lblMsg.Text="Hello!"
End Sub
</script>

<html>
<body>

<form runat="server">
<asp:Button OnClick="script1" OnClientClick="script2()"
Text="Click Me" runat="server" />
<br />
<asp:label id="lblMsg" runat="server" />
</form>

<script>
function script2()
{
return confirm('Hello!');
}
</script>

</body>
</html>

The demonstration >>


Button controls Button controls