Question

I have a list of links :

<ul>
    <li><a href="#">Aktuel</a></li>
    <li><a href="#">Business</a></li>
    <li><a href="#">Common</a></li>
    <li><a href="#">Extras</a></li>
</ul>

I have to add a css class to one of the links. I will have to do it in codebehind with C#. The result should be something like this :

....
<li><a href="#" class="active">Business</a></li>
....

On which life cycle event should I do it and how?

Note : I cant change the html design.

Thanx in advance.

Was it helpful?

Solution

You can register a ClientScript.RegisterStartupScript on the CodeBehind, to run a jQuery script and do the job.

Complete solution, including the ASP.NET bit:

string jsScript = "$(function () { $(\"a:contains('Aktuel')\").addClass(\"active\"); });";

ClientScript.RegisterStartupScript(typeof(Page), "anythingYouFancy", jsScript, true);

You can check it working here (not the ASP.NET part tough):

http://jsfiddle.net/JwkAe/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top