Postback XML Demo

This demo illustrates how a menu item, when clicked, can cause a postback. To configure a menu item to cause a postback you simply need to provide a <commandname> XML element in the <menuItem> element. (See the XML file for an example...).

When a menu item is clicked that causes a postback, the page is posted back and the Menu's MenuItemClicked event is raised, passing along the clicked menu item's commandname in the EventArgs parameter.

Note: Only the book menu items, when clicked, will cause a postback. The 4GuysFromRolla.com menu item and the subitems in the "My Hobby Web Sites" will, when clicked, take you to the specified URL. The menu items in the "My Books" submenu, however, will cause a postback and display the commandname in the Label...

View the XML file bound to the DataGrid, PostbackXML.xml...


Postback result:


Source Code
HTML Portion:
				
<%@ Register TagPrefix="cc1" Namespace="skmMenu" Assembly="skmMenu" %>
<cc1:Menu id="Menu2" runat="server" Font-Names="Arial" Font-Size="Small" BackColor="#E0E0E0"
	Cursor="Pointer" ItemSpacing="0" ItemPadding="5">
	<SelectedMenuItemStyle BackColor="#FFC080"></SelectedMenuItemStyle>
</cc1:Menu>
				
Code-Behind Code:
				
private void Page_Load(object sender, System.EventArgs e)
{
	if (!Page.IsPostBack) {
		Menu1.DataSource = Server.MapPath("SimpleXML.xml");
		Menu1.DataBind();
	}
}

private void Menu1_MenuItemClick(object sender, skmMenu.MenuItemClickEventArgs e)
{
	results.Text = "You clicked a menu item whose <code>commandname</code> is: " + e.CommandName;
}