I have a farm wide feature that overrides the suite control, the substance of which is similar to the following:

public partial class SuiteLinksDelegateCtrl : UserControl
        protected void Page_Load(object sender, EventArgs e)

        protected override void Render(HtmlTextWriter writer)

            // Add CSS class to fix logo image height in subsites

            writer.Write(".ms-core-suiteLinkList {display: inline-block;}");

            // Hide elements pre-loading
            //writer.Write("#s4-bodyContainer {display: none;}");

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "ms-core-suiteLinkList");

            // todo: replace with SQL database call?
            // build out menu links
            AddSuiteLink(writer, "http://sharepoint", "Groups", "lnkGroups");
            AddSuiteLink(writer, "http://sharepoint", "Documents", "lnkDocuments");
            AddSuiteLink(writer, "http://sharepoint", "Projects", "lnkProjects");
            AddSuiteLink(writer, "http://sharepoint", "Services", "lnkServices");
            AddSuiteLink(writer, "http://sharepoint", "Teams", "lnkTeams");

            AddSuiteLink(writer, "http://sharepointpersonal/default.aspx", "Newsfeed", "lnkNewsfeed");
            AddSuiteLink(writer, "http://sharepointpersonal/_layouts/15/MySite.aspx?MySiteRedirect=AllSites", "Followed Sites", "lnkFollowedSites");


            writer.Write("<script src='http://sharepoint/scripts/jquery-1.10.2.min.js'></script>");
            writer.Write("<script src='http://sharepoint/scripts/avdw-pkg.js'></script>");
            writer.Write("<script src='http://sharepoint/scripts/menu.js'></script>");
            writer.Write("<link rel='stylesheet' type='text/css' href='http://sharepoint/scripts/tiles.css' />");


        protected static void FixHeaderStylesHeight(HtmlTextWriter writer)
            writer.Write(".ms-siteicon-img { max-height: 80px; }");

        /// <summary>
        /// Add a new link to the suite bar
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="url"></param>
        /// <param name="name"></param>
        /// <param name="linkId"></param>
        protected static void AddSuiteLink(HtmlTextWriter writer, string url, string name, string linkId)
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "ms-core-suiteLink");
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "ms-core-suiteLink-a");
            writer.AddAttribute(HtmlTextWriterAttribute.Href, url);
            writer.AddAttribute(HtmlTextWriterAttribute.Id, linkId);
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "ms-verticalAlignMiddle");

I have a requirement to write some different CSS to this area when I'm on the main page, but not when I'm on the others.


// Hide elements pre-loading
writer.Write("#s4-bodyContainer {display: none;}");

Should only execute if I'm on the home page, and not on any other page. Is something like this possible?


SOME UNREQUESTED ADVICE: You're doing a lot of crazy stuff in your control, adding jQuery in the Suites delegate and then not using it? if that is used somewhere else and/or globally take a look at the AdditionalPageHead delegate and use your own .ascx to add these things, there's no reason you should be doing this in the code behind. Even better if you have access to the masterpage.

That said, if you know the home and consider it to be static in its address you can simply check for:

if(Request.Url.AbsolutePath.EndsWith("/Home.aspx") || SPContext.Current.Site.ServerRelativeUrl == "/")
    //do stuff

You can also know the SharePoint Home based on the WelcomePage settings:

using(var web = SPContext.Current.Site.OpenWeb(SPContext.Current.Site.ServerRelativeUrl))
    var home = web.RootFolder.WelcomePage;

And then compare it to the Request.Url.AbsolutePath bits above.

  • JQuery is being used within the suite delegate, just not in this area (not everything included above) - more going on here then is explained in the post. – Michael A Nov 19 '13 at 1:11
  • Is there a way to have this not execute when I'm editing the page, only when the page is in display mode? – Michael A Nov 19 '13 at 1:15
  • Yes but doesn't have a definitive answer, take a look at stackoverflow.com/questions/9478913/… – Francisco Aquino Nov 19 '13 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.