Teddy O
Teddy O

Reputation: 21

CssClass not Changing in Asp.net Website

I am using a MasterPage for my website, with various tabs that are placed in the the header (of the MasterPage). The code for the tabs looks like (written in C#):

<ul id="tabMenu">                 
    <li><asp:HyperLink ID="homeLink" runat="server" onclick="homeButton_Click()" 
         NavigateUrl="~/Default.aspx">Home</asp:HyperLink></li>
</ul>

This of course is a single tab, but the rest are very similar. Clicking this link triggers the homeButton_Click() in the code behind, which looks like:

protected void Button1_Click(object sender, EventArgs e)
{
    homeLink.CssClass.Insert(0, "activeTab");
}

The only difference in the current CSS class to the intended one (activeTab) is the change of the background-image. Currently when I click on this tab the CSS class does not change, and the color stays the same.

Any suggestions as to what I'm doing wrong?

Upvotes: 0

Views: 470

Answers (2)

Rahul.R.Parmar
Rahul.R.Parmar

Reputation: 84

You can assign cssclass using below code

homeLink.Attributes.Add("class", "abc");

Upvotes: 1

c0deNinja
c0deNinja

Reputation: 3986

Have you tried setting the css class like this instead:

homeLink.CssClass = "activeTab";

Upvotes: 1

Related Questions