ComponentOne Menu for ASP.NET AJAX: Menu for ASP.NET Task-Based Help > Creating a Click Event for a Menu Item

Creating a Click Event for a Menu Item

To create a click event for a menu item, complete the following:

1.   Add C1Menu control to your page.

2.   Add two menu link items using the C1Menu Designer Form. For more information on adding menu items using the C1Menu Designer Form see, Working with the C1Menu Designer Form.

3.   Add a Label control to your page.

4.   Add the following code to the Page_Load event:

      Visual Basic

Protected Sub C1Menu1_ItemClick(ByVal sender As Object, ByVal e As C1.Web.UI.Controls.C1Menu.C1MenuEventArgs) Handles C1Menu1.ItemClick

        C1.Web.UI.Controls.C1Menu.C1MenuItem itemclicked = e.Item

       

        Label1.Text = "You selected " + itemclicked.Text

End Sub

      C#

protected void C1Menu1_ItemClick(object sender, C1.Web.UI.Controls.C1Menu.C1MenuEventArgs e)

    {

        C1.Web.UI.Controls.C1Menu.C1MenuItem itemclicked = e.Item;

       

        Label1.Text = "You selected " + itemclicked.Text;

    }

5.   Run the project and the menu item looks like the following:

 

6.   Click on the first link item.

The C1Menu1_ItemClick event fires and adds the text to the label.

 


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.