views:

907

answers:

1

Hi,

I have an ASP.NET / C# application in which the Master Page contain the main menu of my application and several content pages that depend of this master page.

I would like to highlight the menu link of my master page corresponding to the current content page displayed.

To do that, I already have a CSS class dedicated to this (called "selected")

Thus, I was trying to access the Master Page link I want to highlight from the content page by using its ID and do something like that (in the content page) :

HtmlLink currentMenu = (HtmlLink) Master.FindControl("idOfTheLinkToHighlight");
currentMenu.Attributes.Add("class", "selected");

But I get the following exception :

Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlGenericControl' to type 'System.Web.UI.HtmlControls.HtmlLink

Can anybody help me on this ? Thanks

A: 

By the way, try

(HtmlGenericControl)currentMenu = (HtmlGenericControl) Master.FindControl("idOfTheLinkToHighlight");
currentMenu.Attributes.Add("class", "selected");

it should work because HtmlGenericControl has also attributes

Gregoire
Yes exactly ! Just the time for e to refresh this page and it is what I tried. It works fine (and my problem was just a mistake that came to my mind thanks to your first answer ;)