by jasonrshaver
6. September 2011 21:43
Setup
This example is assuming Interprise 5.6.22 and Telerik.Web.UI version 2011.2.712, but any recent Telerik version should work fine.
Add the following DLLs to the \bin directory. You can locate them in your \Program Files directory.
- Telerik.Web.Design.dll (not needed for most people, but might as well put it there)
- Telerik.Web.UI.dll
- Telerik.Web.UI.Skins.dll (not needed if you don’t want to use any embedded skins)
- Telerik.Web.UI.XML
Customize App_Code\SkinBase.cs
Edit your App_Code\SkinBase.cs file, but make sure you make a backup. It is really easy to kill your site. Also note that if you start changing this file on a live site, you can cause errors for customers who happen to be using the site at the time.
Add the following code to the “Find Menu” region (around Line 592)
- private void FindTelerikMenu(Control context, List<WebControl> foundMenus)
- {
- foreach (Control ctrl in context.Controls)
- {
- if (ctrl is Telerik.Web.UI.RadMenu) // || ctrl is ComponentArt.Web.UI.Menu)
- {
- foundMenus.Add(ctrl as WebControl);
- }
- else
- {
- // recurse
- FindTelerikMenu(ctrl, foundMenus);
- }
- }
- }
Add the following code to the “SetupMenu” region (around line 432)
- private void SetupTelerikMenu()
- {
- HtmlForm frm = this.ThisForm;
- if (frm == null)
- return;
-
- if (frm.FindControl("ScriptManager") == null)
- {
- Panel pnlScriptManager = new Panel();
- pnlScriptManager.ID = "pnlTelerikScriptManager";
-
- RadScriptManager manager = new RadScriptManager();
- manager.ID = "ScriptManager";
- manager.EnableScriptCombine = false;
- frm.Controls.AddAt(0, manager);
-
- // allow page to register scripts and web services
- RegisterScriptsAndServices(manager);
- }
-
- List<WebControl> foundMenus = new List<WebControl>();
- FindTelerikMenu(this, foundMenus);
-
- if (foundMenus.Count == 0)
- return;
-
- string randomId = Guid.NewGuid().ToString("N").Substring(0, 5);
- // make ready the scripts
- StringBuilder script = new StringBuilder();
- script.AppendFormat("<script type=\"text/javascript\" language=\"Javascript\">\n");
- script.AppendFormat(" function loadMenu_{0}() {{\n", randomId);
-
- foreach (WebControl foundMenu in foundMenus)
- {
- Telerik.Web.UI.RadMenu telerikMenu = foundMenu as Telerik.Web.UI.RadMenu;
-
- string menuId = telerikMenu.ID;
- string containerId = menuId + "_Panel";
- Panel placeHolder = new Panel();
- placeHolder.ID = containerId;
- int originalIndex = FindParentIndex(telerikMenu);
-
- Control parentControl = telerikMenu.Parent;
- parentControl.Controls.Remove(telerikMenu);
- parentControl.Controls.AddAt(originalIndex, placeHolder);
- frm.Controls.Add(telerikMenu);
- telerikMenu.Style["display"] = "none";
-
- SiteMapDataSource ds = new SiteMapDataSource();
- ds.Provider = ISESiteMapProviderFactory.Instance.GetProvider(ThisCustomer.LocaleSetting);
- telerikMenu.DataSource = ds;
- telerikMenu.DataBind();
-
- script.AppendFormat(" var menu_{0} = document.getElementById('{0}');\n", menuId);
- script.AppendFormat(" var panel_{0} = document.getElementById('{0}');\n", containerId);
- script.AppendFormat(" if(menu_{0} && panel_{1}) {{\n", menuId, containerId);
- script.AppendFormat(" panel_{1}.appendChild(menu_{0});\n", menuId, containerId);
- script.AppendFormat(" menu_{0}.style.display = '';\n", menuId, containerId);
- script.AppendFormat(" }}\n");
- }
- script.AppendFormat(" }}\n");
- script.AppendFormat(" $add_windowLoad(loadMenu_{0});\n", randomId);
- script.AppendFormat("</script>\n");
-
- Page.ClientScript.RegisterStartupScript(this.GetType(), randomId, script.ToString());
- }
Change the OnPreRender method (around 396) from SetupMenu() To SetupTelerikMenu(). If you ever wish to undo these changes, this is really the only line that you need to change back.
Changing Your Template
In your template.ascx for your skin (\Skins\Skin_1 is the default), add the following with the other Registers at the top (line 3 or 4 usually):
- <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
Replace everything in the “horizNav” div with the following:
- <!-- TOP MENU -->
- <telerik:RadMenu runat="server" ID="aspnetMenu" Skin="TTX" EnableEmbeddedSkins="false" />
- <!-- END TOP MENU -->
If you want to use a default Telerik skin, replace TTX with the name of the skin you want to use and change EnableEmbeddedSkins to true.
For a custom skin, replace ‘TTX’ with the name of your custom CSS skin for the menu and add the required CSS entries such as:
- /*
- Highligh color = D94A46 (Red)
- Font Color = AAAAAA (darker gray)
- Background color = F8F8F8 (light silver)
- */
- .RadMenu_TTX
- {
- text-align: left;
- margin: 0px;
- padding: 2px;
- }
- /* Root */
- .RadMenu_TTX .rmLink
- {
- line-height: 24px;
- color: Black;
- position: relative;
- display: inline-block !important;
- }
- .RadMenu_TTX .rmText
- {
- color: #AAA;
- text-decoration: none;
- font-weight: bold;
- font-size: 12pt;
- }
- .RadMenu_TTX .rmLink:hover
- {
- }
- .RadMenu_TTX .rmFocused,
- .RadMenu_TTX .rmExpanded,
- .RadMenu_TTX .rmText:hover
- {
- color: #D94A46;
- }
-
- /* Sub Menus */
- .RadMenu_TTX .rmGroup
- {
- border: 1px solid #AAA;
- }
- .RadMenu_TTX .rmGroup .rmLink
- {
- background: White;
- }
- .RadMenu_TTX .rmGroup .rmFocused,
- .RadMenu_TTX .rmGroup .rmExpanded,
- .RadMenu_TTX .rmGroup .rmText
- {
- background: White;
- font-weight: normal;
- font-size: 10pt;
- color: #AAA;
- }
- .RadMenu_TTX .rmGroup .rmLink:hover
- {
- background: #D94A46;
- }
- .RadMenu_TTX .rmGroup .rmText:hover
- {
- color: #D94A46;
- }
And you should be done. All-in-all, it will take you longer to get your CSS file right than it will to do the ‘hard stuff’