Apply to
Menu, SlideMenu, TabStrip and TreeView
Source Code Location
Live demo is available at our website:
http://www.essentialobjects.com/demo/default.aspx?id=menu_server_event.
Source code for demo project can be launched from:
Start -> Programs -> EO.Web Controls x.x -> EO.Web for ASP.NET x.x
-> Live Demo
If your installation directory is "c:\Program Files\Essential Objects", then this
demo is located at: "c:\Program Files\Essential Objects\EO.Web Controls
3.0\Net11\Samples\CS\Demos\Menu\Programming\Server Side Programming".
Demos for .NET 2.0 and VB are also available.
Overview
EO.Web navigation controls raise several events on server side including all the
standard
WebControl events and the following events:
ItemClick Event
ItemClick event is the default event.
It occurs when a navigation item is clicked and the item is configured to raise server
event.
By default, clicking on navigation item does not raise server event.
Either the control'
RaisesServerEvent or the item's RaiseServerEvent
needs to be set properly in order to post back server event. Use the control's
RaisesServerEvent if you want all items in the control to raise
server event; use item's RaisesServerEvent if you want to
control each item individually.
To create a server side event handler:
-
Select the control on your page;
-
Press F4 to display the property window. Go to the event tab, double click on
ItemClick. Visual studio .NET will generate the event handler body
for you.
Here is an example of the event handler body:
[C#]
private void Menu1_ItemClick(object sender,
EO.Web.ItemClickEventArgs e)
{
}
[Visual Basic]
Private Sub Menu1_ItemClick(ByVal sender As System.Object,
ByVal e As EO.Web.ItemClickEventArgs) Handles Menu1.ItemClick
End Sub
Use e.NavigationItem
to refer the item that raised the event.
For example, use e.NavigationItem.ItemID
to get the ID of the navigation item that is clicked by user.
You can also the NavigationItem to a specific type if you know the item type. For example,
if the navigation control is a menu, you can case e.NavigationItem to MenuItem.
When both client event and server event handler are defined, client event
handler is executed before server event handler.
ItemCreated Event
When a new navigation item is created during data binding, EO.Web navigation controls
raise ItemCreated event.
The event argument contains a reference to the newly
created navigation item. Use this event to modify the custom item before it is
rendered.
When the custom item contains other server controls and you want to handle those controls'
server side event, you should hook up those controls' event handler in ItemCreated event.
CustomItemCreated Event
EO.Web navigation controls raise CustomItemCreated
event when an embedded custom item is created. An embedded custom item is
created for each navigation item that has a declared embedded
custom item or each navigation item created during data binding that are
based on a template item that has a
declared embedded custom item. Use this event to modify the custom item before
it is rendered.
Refer to custom item for more information.
ItemDataBound Event
EO.Web navigation controls raise ItemDataBound
event when a navigation item is bound to a data item. Use this event and
item's DataItem property together to make
changes to the navigation item corresponding to the data source.