6

I have this in my master page.

<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="CreateSSCSite">
    <SharePoint:CssLink runat="server" Version="4"/>
</Sharepoint:SPSecurityTrimmedControl>

If the user meets the permissions then it returns:

<span>
    <link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=oiylGAjBYhJ%2Bvc6V%2B0b7wg%3D%3D"/>
</span>

How can I make it not return those infernal span tags?

3 Answers 3

8

Adding to iambriansreed's solution, you can put the comments in Literal controls around the SPSecurityTrimmedControls to prevent SPD from adding the extra rubbish. For example:

<asp:Literal runat="server" text="&lt;!-- "/><SharePoint:SPSecurityTrimmedControl PermissionsString="EditListItems" runat="server"><asp:Literal runat="server" text=" --&gt;"/>
    <link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=oiylGAjBYhJ%2Bvc6V%2B0b7wg%3D%3D"/>
<asp:Literal runat="server" text="&lt;!-- "/></SharePoint:SPSecurityTrimmedControl><asp:Literal runat="server" text=" --&gt;"/>

It's a bit annoying, but simpler than writing a new control.

If you're using SharePoint 2013's Publishing Infrastructure, the same example will look like this on an HTML master page:

<!--SPM:<asp:Literal Text="&lt;!&#45;&#45; " runat="server" />-->
<!--MS:<SharePoint:SPSecurityTrimmedControl runat="server" Permissions="CreateSSCSite">-->
<!--SPM:<asp:Literal Text=" &#45;&#45;&gt;" runat="server" />-->
    <link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=oiylGAjBYhJ%2Bvc6V%2B0b7wg%3D%3D"/>
<!--SPM:<asp:Literal Text="&lt;!&#45;&#45; " runat="server" />-->
<!--ME:</SharePoint:SPSecurityTrimmedControl>-->
<!--SPM:<asp:Literal Text=" &#45;&#45;&gt;" runat="server" />-->
1
  • 1
    Thank goodness that in SharePoint 2013 the heinous SP Designer is going away and other text editors can be used. :) Nov 26, 2012 at 3:01
4

The easiest and cleanest way to do this is wrap the control with html comments:

<!-- <Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="CreateSSCSite"> -->
    <SharePoint:CssLink runat="server" Version="4"/>
<!-- </Sharepoint:SPSecurityTrimmedControl> -->

If the user meets the permissions then it returns:

<!-- <span> -->
    <link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=oiylGAjBYhJ%2Bvc6V%2B0b7wg%3D%3D"/>
<!-- </span> -->

Super simple.

2
  • Hiding the span tag this way is OK but in the editor mode SPD adds a bunch of crap. I am now looking for an alternative. Mar 27, 2012 at 14:40
  • Clever. Very clever.
    – CBono
    Oct 29, 2012 at 19:24
3

You should be able to create your own control inheriting from Sharepoint:SPSecurityTrimmedControl and override RenderBeginTag and RenderEndTag to do nothing

4
  • 1
    I read about that but it is amazingly ridiculous just to get SP not to print a span tag. Mar 20, 2012 at 16:54
  • Yes, but SPSecurityTrimmedControl inherits from the ASP.Net WebControl, which is the one rendering the span tag Mar 20, 2012 at 16:59
  • Can this be done without deploying a WSP? Mar 27, 2012 at 14:25
  • No, this requires an WSP Mar 27, 2012 at 15:38

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.