title: Access an HTML control on ASP Master Page from the code behind of a Content Page
body: <p>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.</p>
  
  <p>I would like to highlight the menu link of my master page corresponding to the current content page displayed.</p>
  
  <p>To do that, I already have a CSS class dedicated to this (called "selected")</p>
  
  <p>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) :</p>
  
  <pre><code>HtmlLink currentMenu = (HtmlLink) Master.FindControl("idOfTheLinkToHighlight");
  currentMenu.Attributes.Add("class", "selected");
  </code></pre>
  
  <p>But I get the following exception :</p>
  
  <pre><code>Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlGenericControl' to type 'System.Web.UI.HtmlControls.HtmlLink
  </code></pre>
  
  <p>Can anybody help me on this ?
  Thanks</p>