Introduction
The simple menu can be applied foremost to navigate among several web forms. Features of the FlatMenu
:
- One-Level menu only (no popup submenus).
- Rendering brief HTML code into
div
and span
(no table tr td
).
- Possibility to invocate of PostBack for each single menu item.
- No extra worthless JavaScript (except of PostBack sure).
- Distinguished menu item of the just loaded web form.
- Simple, well-arranged XML file data source in one place.
- Horizontal and vertical layout option.
On-line presentation is available at
http://flatmenu.aspweb.cz/ [
^]
Background
The control is based on the
Scott Mitchell's excellent piece of software
skmMenu.
Using the code
Data binding
In the Page_Load
method of the Web Form
flatMenu.DataSource = Server.MapPath("FlatMenu.xml");
flatMenu.DataBind();
or caching menu to avoid access to file system by every request: in Application_Start
(Global.asax.cs)
XmlDocument xmlMenu = new XmlDocument();
xmlMenu.Load(Server.MapPath("FlatMenu.xml"));
Application["flatMenu"] = xmlMenu;
and again the method Page_Load
flatMenu.DataSource = Application["flatMenu"];
flatMenu.DataBind();
XML data source
Example of the structure of the XML file:
<menu>
<item postback="true">
<text>
web form
</text>
<url>
WebForm.aspx
</url>
</item>
<item suppresspostback="true">
<text>
other web form
</text>
<url>
OtherWebForm.aspx
</url>
</item>
<item>
<text>
CodeProject site
</text>
<url>
http://www.codeproject.com
</url>
</item>
</menu>
Attribute postback
means click on this menu item raises the postback. When active (current loaded) menu item has attribute supresspostback="true"
then every other menu items behave as common a
tag, so no postback raises.
Active menu item
The HTML tag belong to menu item of just loaded web form has this class attribute:
span class="activeHoriz"
, for horizontal menu layout
div class="activeVert"
, for vertical menu layout
CSS design
For customize design by CSS is important how the menu is rendered into the HTML code.
Horizontal rendering:
<div id="idFlatMenu">
<span><a></a></span>
<span class="activeHoriz"></span>
<span><a></a></span>
</div>
Vertical rendering:
<div id="idFlatMenu">
<div><a></a></span>
<div class="activeVert"></span>
<div><a></a></span>
</div>