Here is the code behind for the master page...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class MsMasterMenu1 : System.Web.UI.MasterPage
{
public String ActiveMenu
{
get
{
object obj = ViewState["ActiveMenu"];
return (obj == null) ? String.Empty : (string)obj;
}
set
{
ViewState["ActiveMenu"] = value;
}
}
public String ActiveMenuContainer
{
get
{
object obj = ViewState["ActiveMenuContainer"];
return (obj == null) ? String.Empty : (string)obj;
}
set
{
ViewState["ActiveMenuContainer"] = value;
}
}
public String ActiveMenuDataFile
{
get
{
object obj = ViewState["ActiveMenuDataFile"];
return (obj == null) ? String.Empty : (string)obj;
}
set
{
ViewState["ActiveMenuDataFile"] = value;
}
}
public String ActiveMenuXPath
{
get
{
object obj = ViewState["ActiveMenuXPath"];
return (obj == null) ? String.Empty : (string)obj;
}
set
{
ViewState["ActiveMenuXPath"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState.Add("ActiveMenu", "");
ViewState.Add("ActiveMenuContainer", "");
ViewState.Add("ActiveMenuDataFile", "");
ViewState.Add("ActiveMenuXPath", "");
}
if (this.ViewState["ActiveMenu"].ToString() != "")
{
this.CreateMenu(this.ViewState["ActiveMenu"].ToString(),
this.ViewState["ActiveMenuContainer"].ToString(),
this.ViewState["ActiveMenuDataFile"].ToString(),
this.ViewState["ActiveMenuXPath"].ToString());
}
}
public void CreateMenu(string pstrMenuName, string
pstrActiveMenuContainer, string pstrActiveMenuDataFile, string
pstrActiveMenuXPath)
{
Menu WebMenu = new Menu();
XmlDataSource xds = new XmlDataSource();
xds.DataFile = pstrActiveMenuDataFile;
xds.ID = pstrMenuName + "XmlDs";
xds.XPath = pstrActiveMenuXPath;
WebMenu.Orientation = Orientation.Horizontal;
WebMenu.DataSourceID = xds.ID;
WebMenu.BackColor =
System.Drawing.ColorTranslator.FromHtml("#B5C7DE");
WebMenu.ForeColor =
System.Drawing.ColorTranslator.FromHtml("#284E98");
WebMenu.StaticMenuItemStyle.HorizontalPadding =
System.Web.UI.WebControls.Unit.Pixel(5);
WebMenu.StaticMenuItemStyle.VerticalPadding =
System.Web.UI.WebControls.Unit.Pixel(2);
WebMenu.DynamicHoverStyle.BackColor =
System.Drawing.ColorTranslator.FromHtml("#284E98");
WebMenu.DynamicHoverStyle.ForeColor = System.Drawing.Color.White;
WebMenu.DynamicMenuStyle.BackColor =
System.Drawing.ColorTranslator.FromHtml("#B5C7DE");
WebMenu.StaticSelectedStyle.BackColor =
System.Drawing.ColorTranslator.FromHtml("#507CD1");
WebMenu.DynamicSelectedStyle.BackColor =
System.Drawing.ColorTranslator.FromHtml("#507CD1");
WebMenu.DynamicMenuItemStyle.HorizontalPadding =
System.Web.UI.WebControls.Unit.Pixel(5);
WebMenu.DynamicMenuItemStyle.VerticalPadding =
System.Web.UI.WebControls.Unit.Pixel(2);
WebMenu.StaticHoverStyle.BackColor =
System.Drawing.ColorTranslator.FromHtml("#284E98");
WebMenu.StaticHoverStyle.ForeColor = System.Drawing.Color.White;
WebMenu.StaticSubMenuIndent =
System.Web.UI.WebControls.Unit.Pixel(10);
WebMenu.DynamicHorizontalOffset = 10;
MenuItemBinding binding;
binding = SetItemBinding("Menu", 0, "Text", "");
WebMenu.DataBindings.Add(binding);
binding = SetItemBinding("Item", 1, "Text", "TargetUrl");
WebMenu.DataBindings.Add(binding);
Control ctrlMenuContainer =
this.frmMain.FindControl(pstrActiveMenuContainer);
ctrlMenuContainer.Controls.Add(xds);
ctrlMenuContainer.Controls.Add(WebMenu);
}
protected MenuItemBinding SetItemBinding(String pstrDataMember, Int32
pintDepth, String pstrTextField, String pstrTargetUrlField)
{
MenuItemBinding binding = new MenuItemBinding();
binding.DataMember = pstrDataMember;
binding.Depth = pintDepth;
binding.TextField = pstrTextField;
binding.NavigateUrlField = pstrTargetUrlField;
return binding;
}
protected void btnCreateMenu_Click(object sender, EventArgs e)
{
this.ActiveMenu = "TestMenu";
this.ActiveMenuContainer = "MasterMenuPanelA";
this.ActiveMenuDataFile = "~/Menu.xml";
this.ActiveMenuXPath = "/Root/Menu";
this.CreateMenu(this.ActiveMenu, this.ActiveMenuContainer,
this.ActiveMenuDataFile, this.ActiveMenuXPath);
}
}
here is the html from the master page...
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MsMasterMenu1.master.cs" Inherits="MsMasterMenu1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test Master Menu Page</title>
</head>
<body>
<form id="frmMain" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%;
height: 100%">
<tr>
<td colspan="2" style="height: 200px">
TODO: ...
</td>
</tr>
<tr>
<td style="width: 200px">
TODO: ... <br />
<asp:Button ID="btnCreateMenu" runat="server"
OnClick="btnCreateMenu_Click" Text="Create Menu" />
</td>
<td>
<asp
anel ID="MasterMenuPanelA" runat="server" Height="50px"
Width="125px" >
</asp
anel>
<asp:contentplaceholder id="MainContentPlaceHolder"
runat="server">
</asp:contentplaceholder>
</td>
</tr>
<tr>
<td colspan="2" style="height: 200px">
TODO: ...
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
here is the default consumer page code behind...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ConsumeMsMasterMenu1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
here is the html for the default consumer page...
<%@ Page Language="C#" MasterPageFile="~/MsMasterMenu1.master"
AutoEventWireup="true" CodeFile="ConsumeMsMasterMenu1.aspx.cs"
Inherits="ConsumeMsMasterMenu1" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MsMasterMenu1.master" %>
<asp:Content ID="ContentDefault"
ContentPlaceHolderID="MainContentPlaceHolder" Runat="Server">
Default content page
</asp:Content>
here is the code behind for the select menu item content page...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class SelectMenuItemContentPage1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
here is the html for the select menu item content page...
<%@ Page Language="C#" MasterPageFile="~/MsMasterMenu1.master"
AutoEventWireup="true" CodeFile="SelectMenuItemContentPage1.aspx.cs"
Inherits="SelectMenuItemContentPage1" Title="Untitled Page" %>
<asp:Content ID="ContentMenuItem1"
ContentPlaceHolderID="MainContentPlaceHolder" Runat="Server">
Selected item from menu content page
</asp:Content>