LinkButton.Command 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在单击 LinkButton 控件时发生。
public:
event System::Web::UI::WebControls::CommandEventHandler ^ Command;
public:
virtual event System::Web::UI::WebControls::CommandEventHandler ^ Command;
public event System.Web.UI.WebControls.CommandEventHandler Command;
member this.Command : System.Web.UI.WebControls.CommandEventHandler
Public Custom Event Command As CommandEventHandler
事件类型
实现
示例
下面的示例演示如何为 事件指定和编码处理程序, Click 以便在单击控件时 LinkButton 显示消息。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>LinkButton Command Event Example</title>
<script language="C#" runat="server">
void LinkButton_Command(Object sender, CommandEventArgs e)
{
Label1.Text = "You chose: " + e.CommandName + " Item " + e.CommandArgument;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>LinkButton Command Event Example</h3>
<asp:LinkButton id="LinkButton1"
Text="Order Item 10001"
CommandName="Order"
CommandArgument="10001"
OnCommand="LinkButton_Command"
runat="server"/>
<br />
<asp:LinkButton id="LinkButton2"
Text="Order Item 10002"
CommandName="Order"
CommandArgument="10002"
OnCommand="LinkButton_Command"
Runat="server"/>
<br />
<br />
<asp:Label id="Label1" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>LinkButton Command Event Example</title>
<script language="VB" runat="server">
Sub LinkButton_Command(sender As Object, e As CommandEventArgs)
Label1.Text = "You chose: " & e.CommandName & " Item " & _
e.CommandArgument
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>LinkButton Command Event Example</h3>
<asp:LinkButton id="LinkButton1"
Text="Order Item 10001"
CommandName="Order"
CommandArgument="10001"
OnCommand="LinkButton_Command"
runat="server"/>
<br />
<asp:LinkButton id="LinkButton2"
Text="Order Item 10002"
CommandName="Order"
CommandArgument="10002"
OnCommand="LinkButton_Command"
Runat="server"/>
<br />
<br />
<asp:Label id="Label1" runat="server"/>
</form>
</body>
</html>
注解
单击 Command 控件时, LinkButton 将引发 事件。 当命令名称(如 Sort
)与 LinkButton 控件关联时,通常使用此事件。 这允许你在网页上创建多个 LinkButton 控件,并通过编程方式确定单击哪个 LinkButton 控件。
注意
事件 Command 通过控件层次结构以 的形式 BubbleEvent
引发。
有关如何处理事件的详细信息,请参阅 处理和引发事件。