LinkButton.OnCommand(CommandEventArgs) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤의 Command 이벤트를 발생 줍니다 LinkButton .
protected:
virtual void OnCommand(System::Web::UI::WebControls::CommandEventArgs ^ e);
protected virtual void OnCommand(System.Web.UI.WebControls.CommandEventArgs e);
abstract member OnCommand : System.Web.UI.WebControls.CommandEventArgs -> unit
override this.OnCommand : System.Web.UI.WebControls.CommandEventArgs -> unit
Protected Overridable Sub OnCommand (e As CommandEventArgs)
매개 변수
이벤트 데이터를 포함하는 A CommandEventArgs 입니다.
예제
다음 예제에서는 지정 하 고 클릭 하는 컨트롤을 표시 하는 이벤트에 대 한 Command 처리기를 코딩 하는 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통해 발생합니다.
이벤트를 발생시키는 경우 대리자를 통해 이벤트 처리기가 호출됩니다. 자세한 내용은 이벤트 처리 및 발생을 참조하세요.
또한 이 OnCommand 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다. 파생 클래스에서 이벤트를 처리하기 위한 기본 설정 기술입니다.
상속자 참고
파생 클래스에서 재정의하는 OnCommand(CommandEventArgs) 경우 등록된 대리자가 이벤트를 받도록 기본 클래스의 OnCommand(CommandEventArgs) 메서드를 호출해야 합니다.