Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

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" />-->
share|improve this answer
    
That extra garbage was a huge pain. Thanks alot! –  iambriansreed Nov 26 '12 at 3:00
    
Thank goodness that in SharePoint 2013 the heinous SP Designer is going away and other text editors can be used. :) –  iambriansreed Nov 26 '12 at 3:01

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.

share|improve this answer
    
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. –  iambriansreed Mar 27 '12 at 14:40
    
Clever. Very clever. –  CBono Oct 29 '12 at 19:24

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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