请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
Button 类
Button 事件
 Click 事件

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
Button.Click 事件

在单击 Button 控件时发生。

命名空间:System.Web.UI.WebControls
程序集:System.Web(在 system.web.dll 中)

Visual Basic(声明)
Public Event Click As EventHandler
Visual Basic(用法)
Dim instance As Button
Dim handler As EventHandler

AddHandler instance.Click, handler
C#
public event EventHandler Click
C++
public:
virtual event EventHandler^ Click {
    void add (EventHandler^ value) sealed;
    void remove (EventHandler^ value) sealed;
}
J#
/** @event */
public final void add_Click (EventHandler value)

/** @event */
public final void remove_Click (EventHandler value)
JScript
JScript 支持使用事件,但不支持进行新的声明。

当单击 Button 控件时会引发 Click 事件。当没有与 Button 控件(例如 Submit 按钮)关联的命令名时,通常使用该事件。

有关处理事件的更多信息,请参见 使用事件

TopicLocation
如何:实现简单的 Forms 身份验证生成 ASP .NET Web 应用程序
如何:实现简单的 Forms 身份验证在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:将多个事件连接到 ASP.NET 网页中的单个事件处理程序生成 ASP .NET Web 应用程序
如何:将多个事件连接到 ASP.NET 网页中的单个事件处理程序在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中通过代码分离创建基本网页在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中通过代码分离创建基本网页使用 Visual Web Developer 生成应用程序
演练:验证 Web 窗体页中的用户输入在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:验证 Web 窗体页中的用户输入使用 Visual Web Developer 生成应用程序

下面的代码示例演示如何指定和编写 Click 事件的事件处理程序,以便在用户单击 Button 控件时在网页上显示消息。

Visual Basic
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    Sub GreetingBtn_Click(ByVal sender As Object, _
                          ByVal e As EventArgs)
   
        ' When the button is clicked,
        ' change the button text, and disable it.
        
        Dim clickedButton As Button = sender
        clickedButton.Text = "...button clicked..."
        clickedButton.Enabled = False
 
        ' Display the greeting label text.
        GreetingLabel.Visible = True
    End Sub

</script>

<html  >
<head runat="server">
    <title>Button Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <h3>Simple Button Example</h3>
     
      <asp:Button id="Button1"
           Text="Click here for greeting..."
           OnClick="GreetingBtn_Click" 
           runat="server"/>
      <br />
      <br />
      <asp:Label ID="GreetingLabel" runat="server" 
                 Visible=false Text="Hello World!" />
    </div>
    </form>
</body>
</html>
C#
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    void Page_Load(Object sender, EventArgs e)
    {
        // Manually register the event-handling method for
        // the Click event of the Button control.
        Button1.Click += new EventHandler(this.GreetingBtn_Click);
    }

    void GreetingBtn_Click(Object sender,
                           EventArgs e)
    {
        // When the button is clicked,
        // change the button text, and disable it.

        Button clickedButton = (Button)sender;
        clickedButton.Text = "...button clicked...";
        clickedButton.Enabled = false;
        
        // Display the greeting label text.
        GreetingLabel.Visible = true;
    }

</script>

<html  >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <h3>Simple Button Example</h3>
     
      <asp:Button id="Button1"
           Text="Click here for greeting..."
           OnClick="GreetingBtn_Click" 
           runat="server"/>
      <br />
      <br />
      <asp:Label ID="GreetingLabel" runat="server" 
                 Visible=false Text="Hello World!" />
    </div>
    </form>
</body>
</html>

Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

.NET Framework

受以下版本支持:2.0、1.1、1.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker