Click here to Skip to main content
11,481,265 members (65,066 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i want to show active my menu item when i am click on it but the menu is on my masterpage that why i am not able to do this task. can any one guide me??

[EDIT]
<div class="menu_nav">
        <ul>
          <li ><a href="Home.aspx" class="active">Home</a></li>
          <li ><a href="Services.aspx" class="inactive">Services</a></li>
          <li><a href="Aboutus.aspx" class="inactive">About Us</a></li>
          <li><a href="Login.aspx" class="inactive">Login</a></li>
          <li><a href="Contactus.aspx" class="inactive">Contact Us</a></li>
        </ul>
my code in masterpage like this and I want to show active menu item when i am click on it for example when I click on home its highlight home and soon what will I do for it??


moved from answer[/EDIT]
Posted 23-Mar-11 1:25am
Edited 23-Mar-11 3:12am
m@dhu29.6K
v2
Comments
Sandeep Mewara at 23-Mar-11 6:32am
   
Did you try to Google or even CP Search?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You should set value for StaticSelectedStyle-CssClass attribute. It will look like:

<asp:Menu ID="Menu1" runat="server" StaticSelectedStyle-CssClass="yourcssclass">
            <Items>
                <asp:MenuItem Text="Home"></asp:MenuItem>
                <asp:MenuItem Text="About"></asp:MenuItem>
            </Items>
        </asp:Menu>

Please vote if my answer will help you.
  Permalink  
Comments
mkgoud at 23-Mar-11 8:13am
   
op updated his question. Have a look at it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You can do following thing in your Content page :-
Just find control from Master Page ,

HtmlAnchor example = (HtmlAnchor)Master.FindControl("example");
example.class = "selected";

For HtmlAnchor you have to add "System.Web.UI.HtmlControls" namespace.

But it will gives u error in " Example.Class " bcz it won't get class attributes.

See here is the w3 specification for the anchor (a) tag:



1. <!ELEMENT A - - (%inline;)* -(A) -- anchor -->
2. <!ATTLIST A
3. %attrs; -- %coreattrs, %i18n, %events --
4. charset %Charset; #IMPLIED -- char encoding of linked resource --
5. type %ContentType; #IMPLIED -- advisory content type --
6. name CDATA #IMPLIED -- named link end --
7. href %URI; #IMPLIED -- URI for linked resource --
8. hreflang %LanguageCode; #IMPLIED -- language code --
9. rel %LinkTypes; #IMPLIED -- forward link types --
10. rev %LinkTypes; #IMPLIED -- reverse link types --
11. accesskey %Character; #IMPLIED -- accessibility key character --
12. shape %Shape; rect -- for use with client-side image maps --
13. coords %Coords; #IMPLIED -- for use with client-side image maps --
14. tabindex NUMBER #IMPLIED -- position in tabbing order --
15. onfocus %Script; #IMPLIED -- the element got the focus --
16. onblur %Script; #IMPLIED -- the element lost the focus --
17. >

As you can see, there's no class attribute there, so this is just me being a moog.

Annoyingly, it looks like there's no easy way to do what I'm trying to do using the HTML anchor,
so I'll have to use some other element (such as an ASP.NET Button, or something or server Control <asp:HyperLink>). No big deal.


=============================================================
If You use <asp:hyperlink xmlns:asp="#unknown"> then thing will be easy for you,

Master.master Page :-

<asp:hyperlink id="tab_home" runat="server" navigateurl="ABC.aspx" />
<asp:hyperlink id="tab_login" runat="server" navigateurl="" />

On Content Page : (Here ABC.aspx)

Just Find Ur Control from master page like this

HyperLink hlCart = (HyperLink)Master.FindControl("tab_cart");
hlCart.CssClass = "selected";

Here you can assign CSSCLASS="SELECTED".

I Hope this will Help you.
All d best
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

In your master page add the following code....

Private mSelMenuItem as string = nothing
 
Public property SelMenuItem as string
  get
    return mSelMenuItem
  end get
  set (value as string)
    mSelMenuitem = value
  end set
end property
 
Public Function GetMyMenuState(ForThisMenuItem as string) as string
  If ForThisMenuItem = mSelMenuItem Then
    Return ("class=" & chr(34) & "active" & chr(34) & " ")
  Else
    Return ("class=" & chr(34) & "inactive" & chr(34) & " ")
  End If
End Function


then... in EACH of your CONTENT Pages in the form load event add a SINGLE statement to identify the page to the master page...
like this for the homepage...
  me.master.SelMenuItem = "Home"

or like this for services page

  me.master.SelMenuItem = "Services"


Then in your masterpage where the menu is....
you can use it like this ...

<li><a href="homepage.aspx" <%=GetMyMenuState("Home") %>>Home</a></li>
<li><a href="services.aspx" <%=GetMyMenuState("Services") %>>Services</a></li>
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 294
1 OriginalGriff 225
2 CPallini 135
3 CHill60 120
4 Richard MacCutchan 80
0 Sergey Alexandrovich Kryukov 8,184
1 OriginalGriff 7,701
2 Sascha Lefèvre 3,114
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100