MenuEventHandler Delegato
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta il metodo che gestisce l'evento o MenuItemClick l'evento MenuItemDataBound di un Menu controllo .
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)
Parametri
- sender
- Object
La fonte dell'evento.
Oggetto MenuEventArgs contenente i dati dell'evento.
Esempio
Nell'esempio di codice seguente viene illustrato come utilizzare il MenuEventHandler delegato per registrare a livello di codice un gestore eventi per l'evento MenuItemClick di un Menu controllo. Per il corretto funzionamento di questo esempio, è necessario copiare i dati della mappa del sito di esempio di seguito in un file denominato 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>
Di seguito sono riportati i dati della mappa del sito di esempio per l'esempio precedente.
<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>
Commenti
La MenuEventHandler classe viene utilizzata per rappresentare il metodo che gestisce gli eventi nella tabella seguente.
| Evento | Descrizione |
|---|---|
| MenuItemClick | Si verifica quando si fa clic su una voce di menu. Questo evento viene comunemente usato per sincronizzare un Menu controllo con un altro controllo nella pagina. |
| MenuItemDataBound | Si verifica quando una voce di menu è associata ai dati. Questo evento viene comunemente usato per modificare una voce di menu prima che venga eseguito il rendering in un Menu controllo . |
Quando si crea un MenuEventHandler delegato, si identifica il metodo che gestirà l'evento. Per associare l'evento al gestore eventi, aggiungere un'istanza del delegato all'evento. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non si rimuovono il delegato. Per altre informazioni sui delegati del gestore eventi, vedere Gestione e generazione di eventi.
Metodi di estensione
| Nome | Descrizione |
|---|---|
| GetMethodInfo(Delegate) |
Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato. |