Sitefinity add class to navigation control template

Posted by Community Admin on 05-Aug-2018 16:11

Sitefinity add class to navigation control template

All Replies

Posted by Community Admin on 24-Jul-2012 00:00

I have a control template in my navigation widget. I am trying to display a border under the current page. In the control template I get the current node in the control template code behind and add the class to display the border.


hyperLink.Attributes.Add("class", "activePrimary");


The hyperlink is rendered with 2 classes.


<a id="ctl00_NavPrimaryTopPlaceholder_C008_ctl00_ctl00_MenuRadListView_ctrl0_MenuItemHyperLink" class="top" class="activePrimary" href="home">Home</a>


I assume Sitefinity is placing the class="top". How can I append my class after the top?


Thanks in advance.

Posted by Community Admin on 13-Aug-2012 00:00

Bill,

Dealing with multiple classes can be a pain. I found some code, a while back, that has been useful.
public static class WebHelper
    public static void AddCssClass(this WebControl control, string cssClass)
    
        List<string> classes;
        if (!string.IsNullOrWhiteSpace(control.CssClass))
        
            classes = control.CssClass.Split(new[] ' ' , StringSplitOptions.RemoveEmptyEntries).ToList();
            if (!classes.Contains(cssClass))
                classes.Add(cssClass);
        
        else
        
            classes = new List<string> cssClass ;
        
        control.CssClass = string.Join(" ", classes.ToArray());
    
 
    public static void RemoveCssClass(this WebControl control, string cssClass)
    
        List<string> classes = new List<string>();
        if (!string.IsNullOrWhiteSpace(control.CssClass))
        
            classes = control.CssClass.Split(new[] ' ' , StringSplitOptions.RemoveEmptyEntries).ToList();
        
        classes.Remove(cssClass);
        control.CssClass = string.Join(" ", classes.ToArray());
    

This thread is closed