MenuEventHandler 대리자

정의

MenuItemClick 컨트롤의 MenuItemDataBound 이벤트 또는 Menu 이벤트를 처리하는 메서드를 나타냅니다.

public delegate void MenuEventHandler(System::Object ^ sender, MenuEventArgs ^ e);
public delegate void MenuEventHandler(object sender, MenuEventArgs e);
type MenuEventHandler = delegate of obj * MenuEventArgs -> unit
Public Delegate Sub MenuEventHandler(sender As Object, e As MenuEventArgs)

매개 변수

sender
Object

이벤트 소스입니다.

e
MenuEventArgs

이벤트 데이터를 포함하는 MenuEventArgs입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 MenuEventHandler 프로그래밍 방식으로 이벤트 처리기를 등록 하는 대리자를 MenuItemClick 의 이벤트를 Menu 컨트롤. 제대로 작동 하려면이 예제에서는 라는 Web.sitemap 파일에 아래 샘플 사이트 맵 데이터를 복사 해야 합니다.


<%@ 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)
  {
    
    // Create a new Menu control.
    Menu newMenu = new Menu();
          
    // Set the properties of the Menu control.
    newMenu.ID = "NavigationMenu";
    newMenu.Orientation = Orientation.Vertical;
    newMenu.Target = "_blank";

    // Specify the data source for the menu.
    newMenu.DataSourceID = "MenuSource";

    // Programmatically register the event-handling method
    // for the MenuItemClick event of a Menu control. 
    newMenu.MenuItemClick += new MenuEventHandler(this.NavigationMenu_MenuItemClick);

    // Add the Menu control to the Controls collection
    // of the PlaceHolder control.
    MenuPlaceHolder.Controls.Add(newMenu);
    
  }

  void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
  {

    // Display the text of the menu item selected by the user.
    Message.Text = "You selected " + e.Item.Text + ".";

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuEventHandler Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuEventHandler Example</h3>
    
      <asp:placeholder id="MenuPlaceHolder"
        runat="server"/>
        
      <asp:sitemapdatasource id="MenuSource"
        runat="server"/>
        
      <hr/>
      
      <asp:label id="Message"
        runat="server"/>  

    </form>
  </body>
</html>

<%@ 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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    
    ' Create a new Menu control.
    Dim newMenu As New Menu()
          
    ' Set the properties of the Menu control.
    newMenu.ID = "NavigationMenu"
    newMenu.Orientation = Orientation.Vertical
    newMenu.Target = "_blank"

    ' Specify the data source for the menu.
    newMenu.DataSourceID = "MenuSource"

    ' Programmatically register the event-handling method
    ' for the MenuItemClick event of a Menu control. 
    AddHandler newMenu.MenuItemClick, AddressOf NavigationMenu_MenuItemClick

    ' Add the Menu control to the Controls collection
    ' of the PlaceHolder control.
    MenuPlaceHolder.Controls.Add(newMenu)
    
  End Sub

  Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)

    ' Display the text of the menu item selected by the user.
    Message.Text = "You selected " & e.Item.Text & "."

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuEventHandler Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuEventHandler Example</h3>
    
      <asp:placeholder id="MenuPlaceHolder"
        runat="server"/>
        
      <asp:sitemapdatasource id="MenuSource"
        runat="server"/>
        
      <hr/>
      
      <asp:label id="Message"
        runat="server"/>  

    </form>
  </body>
</html>

다음은 샘플 사이트 맵 데이터 앞의 예제입니다.

<siteMap>

<siteMapNode title="Home"

description="Home">

<siteMapNode title="Music"

description="Music">

<siteMapNode title="Classical"

description="Classical"/>

<siteMapNode title="Rock"

description="Rock"/>

<siteMapNode title="Jazz"

description="Jazz"/>

</siteMapNode>

<siteMapNode title="Movies"

description="Movies">

<siteMapNode title="Action"

description="Action"/>

<siteMapNode title="Drama"

description="Drama"/>

<siteMapNode title="Musical"

description="Musical"/>

</siteMapNode>

</siteMapNode>

</siteMap>

설명

MenuEventHandler 클래스는 다음 표에 이벤트를 처리 하는 메서드를 나타내는 데 사용 됩니다.

이벤트 설명
MenuItemClick 메뉴 항목을 클릭할 때 발생 합니다. 이 이벤트는 일반적으로 동기화 하는 데는 Menu 페이지의 다른 컨트롤과 컨트롤입니다.
MenuItemDataBound 메뉴 항목을 데이터에 바인딩될 때 발생 합니다. 렌더링 하기 전에 메뉴 항목을 수정 하려면이 이벤트는 일반적으로 Menu 제어 합니다.

MenuEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보