Glossary Item Box
While the Navigator Control is building the menu, it raises events. This means that it will run code that you provide (called event handlers) during processing. Your code can change the appearance and content of the resulting menu. This document describes using event handlers to change the appearance of items in the menu.
Three events are raised during the processing of the menu:
| Event | Description |
|---|---|
| TopLevelCreated | Raised after the top-level items have been identified and added to the list of items that will be in the menu. The sub-categories have not yet been added. |
| SubcategoriesCreated | Raised each time a group of sub-categories, all at the same level, have been identified and added to the list of items that will be in the menu. |
| ItemCreated | Raised each time an item is added to the menu from the list described in the other 2 events. |
The best event to use for formatting is ItemCreated. While handling this event, your code can add text or images to the menu item based on the item properties. To add an event handler, you follow these 2 steps:
As a trivial example, the code to add the TotalProductCount after the category name would look like this:
<script runat="server">
Sub AddProductCount(ByVal sender As Object, _
ByVal e As StructuredSolutions.WebControls.NavigatorItemEventArgs)
e.Item.DisplayName &= " (" & e.Item.TotalProductCount & ")"
End Sub
</script>
This script block is added to the user control that contains the Navigator Control. Then the parameter OnItemCreated="AddProductCount" is added to the Navigator Control tag. The sample control TextNavigator4.ascx uses this technique to add an arrow to the item if there are sub-categories.
In this walk through, we will add an event handler to TextNavigator1.ascx that appends the total product count for a category after the category name.
<%@ Control Language="vb" Inherits="System.Web.UI.UserControl" %> <%@ Register TagPrefix="sfaddons"
Namespace="StructuredSolutions.WebControls"
Assembly="SSNavigator" %> <%' © 2005 Structured Solutions %> <script runat="server"> Sub ItemCreated(ByVal sender As Object, _ ByVal e As StructuredSolutions.WebControls.NavigatorItemEventArgs) e.Item.DisplayName &= " (" & e.Item.TotalProductCount & ")" End Sub </script>
<sfaddons:Navigator id="Navigator1" runat="server"
OnItemCreated="ItemCreated">
Open a store page and you will see the effect of your changes.
Copyright © 2005 by Structured Solutions. All rights reserved.
Version 1.3.2