Solved

asp:Menu as tab control problem.

Posted on 2006-11-09
5
843 Views
Last Modified: 2011-09-20
Hello,

I am force to make a tab control like menu to my asp.net website because of no available tab control shipped with VS studio 2005.

Im having problem when clicking one of the menu and launch the page contain. The Menu selected value are reset to default. what i like is to remember the selection i made so i have a proper back-ground color for the selected menu.

I have 4 pages:

MasterPage:   MasterPage.Master
UserControl:   TopMenu.ascx
HomePage:  Home.aspx
Another Page: OtherPage.aspx

Code Below:

"MasterPage.Master"

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs" Inherits="MasterPage" %>
<%@ Register Src="CommonControls/TopMenu.ascx" TagName="TopMenu" TagPrefix="uc1" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>        
        <uc1:TopMenu id="TopMenu1" runat="server">
        </uc1:TopMenu></div>
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>


"TopMenu.ascx"

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TopMenu.ascx.cs" Inherits="TopMenu" %>
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" BackColor="#FFFBD6" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" StaticSubMenuIndent="10px">
    <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
    <DynamicHoverStyle BackColor="#990000" ForeColor="White" BorderWidth="0px" />
    <DynamicMenuStyle BackColor="#FFFBD6" BorderWidth="0px" />
    <StaticSelectedStyle BackColor="#FFCC66" BorderWidth="0px" />
    <DynamicSelectedStyle BackColor="#FFCC66" BorderWidth="0px" />
    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" BorderWidth="0px" />
    <Items>
        <asp:MenuItem Text="Home" Value="Home" NavigateUrl="~/Home.aspx"></asp:MenuItem>
        <asp:MenuItem Text="Other Page" Value="Other Page" NavigateUrl="~/OtherPage.aspx"></asp:MenuItem>
    </Items>
    <StaticHoverStyle BackColor="#990000" ForeColor="White" />
</asp:Menu>

"Home.aspx"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Home" MasterPageFile="~/MasterPage.Master" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server" ID="contentHome">
Home Page
</asp:Content>

"OtherPage.aspx"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OtherPage.aspx.cs" Inherits="OtherPage" MasterPageFile="~/MasterPage.Master" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server" ID="contentOtherPage">
Other Page
</asp:Content>

You can see above that when i click the menu item Home it will go to Home.aspx and Other Page will go to otherpage.aspx. Its ok and no problem. But the active selection of menu will be refresh and get back to default value because usercontrol will then again be called. Because of here i cannot get the feeling of tab control menu like of my website.

Please help. thanks













0
Comment
Question by:apmcph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 

Author Comment

by:apmcph
ID: 17911997
To follow up, i would like to do something like here in experts exchange menu that you will see above.
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 total points
ID: 17913240
Hi apmcph,

hello because you are making post back every time the menu is rebound and looses its clicked item
an approach is to use this method
public void SelectMenu()
    {
        foreach (MenuItem item in Menu1.Items)
        {
            if (System.IO.Path.GetFileName(item.NavigateUrl) == System.IO.Path.GetFileName(this.Request.RawUrl))
                item.Selected = true;
        }
    }

and call it from Page_Load of the MasterPage

Cheers!
0
 

Author Comment

by:apmcph
ID: 17927949
mmarinov,

Thanks... I will try this next week. I was so tied up on meeting schedule.
Will get back to you..

thanks
0
 

Author Comment

by:apmcph
ID: 18073343
Hi mmarinov,

Sorry for very late reply..I was so tied up with tight schedules but as i have promised i will definitely try your solution and it really works.

Though i never really understand as of now how your solution works, i will try to understand this in the next days. The important is it is now working.

Hands up to you.



0
 

Author Comment

by:apmcph
ID: 18075111
Hi mmarinov,

How about if i want to maintain the selected item in my MainMenu when i click any page within that folder. Or to automatically select MainMenu Item when i go to a page under that folder.

Thanks


0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running powershell scripts from ASP.NET 6 79
using CK editor in iframes 5 33
Disable the weekends on datepicker control 6 50
How does this modal work? 3 29
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question