Reputation: 27996
I am working on an asp.net page. I have two hyperlinks and I want to make them active ( apply a style sheet, make bolder and underline) but somehow it is not doing it.
Here is html:
<li style="margin-left: 10px">
<asp:Literal ID="ltrlRegiosn" runat="server" Text="<%$ Resources: HRGELoggedOutMaster, Language %>"></asp:Literal>:
</li>
<li class="active1"> <asp:HyperLink ID="Lang1HyperLink" runat="server" /></li>
<li><asp:HyperLink ID="Lang2HyperLink" runat="server" /></li>
and style sheet is:
<style>
.active1{
font-weight: bold;
}
</style>
and here is how i am trying to do it using code behind:
if (Page.CurrentLanguage == 1)
{
Lang2HyperLink.CssClass = "active1";
Lang2HyperLink.Font.Bold = true;
Lang2HyperLink.Font.Underline = true;
}
else
{
Lang1HyperLink.CssClass = "active1";
Lang1HyperLink.Font.Bold = true;
Lang1HyperLink.Font.Underline = true;
}
With this code, it becomes underlined but not bold.
Here is output html:
<li class="active1"> <a id="ctl00_ctl00_languageSwitcher_Lang1HyperLink" href="/AllVacancies.aspx?lang=2">Рус</a></li>
<li class="active1"><a id="ctl00_ctl00_languageSwitcher_Lang2HyperLink" class="active1" href="/AllVacancies.aspx?lang=1" style="font-weight:bold;text-decoration:underline;">Eng</a></li>
Please suggest how to fix it ?
Upvotes: 0
Views: 8202
Reputation: 11433
There's no need to set the style properties using code behind. when you are already setting the CssClass. Just modify your CSS:
.active1
{
font-weight: bold;
text-decoration:underline;
}
And then you can set just the CssClass via code behind:
if (Page.CurrentLanguage == 1)
{
Lang2HyperLink.CssClass = "active1";
}
else
{
Lang1HyperLink.CssClass = "active1";
}
One more thing: I noticed that you have set the "Active1" class on your <li>
as well:
<li class="active1">
That seems like it might be a typo, or at the very least will be confusing for you. I would remove that.
Upvotes: 4