My master page has the menu. By clicking on the "home" link takes me to home.aspx page. I want the home button to be in a different css while I'm on that page. I came across multiple posts but this one from Jeremy caught my eye and looked simple enough.
https://stackoverflow.com/a/10871099/1851048 .
I tried to implement the same in my website but its not working. I get this: "'System.Web.UI.HtmlControls.HtmlGenericControl' is a type not a namespace"
This is the .cs code in my home.aspx.cs:
using System.Web.UI.HtmlControls.HtmlGenericControl;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
public class HtmlGenericControl : HtmlContainerControl
{
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControls mycontrol = (HtmlGenericControl)this.Page.Master.FindControl("yourcontrolname") as HtmlGenericControl;
mycontrol.Attributes.Add("class", "cssToApply");
}
}
I did some research here: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlgenericcontrol.aspx
But I got different errors each time. I managed to get rid of all of them but then the code wouldn't work.
This is my first website so I currently have a lot to learn. Appreciate your help.
Edit:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var mycontrol = this.Page.Master.FindControl("HyperLink1") as HtmlGenericControl;
mycontrol.Attributes.Add("class", "cssToApply");
}
}
CSS:
#menu ul
{
padding-bottom: 10px;
padding-top: 10px;
list-style: none;
display: inline-block;
}
#menu li
{
margin: auto;
display:inline;
}
#menu a
{
font-family: Verdana;
color: white;
margin: 6px;
float: left;
width: 150px;
height: 27px;
padding: 0 0 0 0;
border-radius: 6px;
text-align: center;
text-decoration: none;
font-size: 1.5em;
}
#menu a:hover
{
background-color: white;
color: #bee2f1;
}
.cssToApply
{
background-color: white;
color: #bee2f1;
}
MasterPage.master:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="home.aspx">Home</asp:HyperLink></li>