2

Considering that in SPD 2010 no inline code is permitted, why on the Asp.net controls panel controls like Repeater, DataList, and FormView are shown, when their usage requires binding expressions (<%# Eval/Bind %>) which are not allowed?

How am I supposed, for example, to use a Repeater in SPD ?

1

2 Answers 2

1

I found a way to use EVAL expression in a legal way in SharePoint Designer and wanted to share it with you.

Say you have a SPDataSource and ASP.Net Repeater control bound to it.

Using EVAL expression like this is not allowed:

<asp:Repeater runat="server" id="Repeater1" DataSourceID="spdatasource1">
  <ItemTemplate>
    <%# Eval('Title') %>
  </ItemTemplate>
</asp:Repeater>

but, if you use the Eval expression inside another ASP.Net control, then it won't complain:

<asp:Repeater runat="server" id="Repeater1" DataSourceID="spdatasource1">
    <ItemTemplate>
       <asp:Literal runat="server" Text="<%# Eval('Title') %>" ID="lit1"></asp:Literal>
    </ItemTemplate>
</asp:Repeater>

I'm so thrilled I've found this solution, as it opens up new possibilities of great customizations done purely in SharePoint Designer.

2
  • Can you explain some of the new things that this enables us to do in Designer that we can't do with SharePoint controls and XSLT? I'm finding myself doing a lot of custom pages in SPD, and I would like to leverage some new techniques where possible.
    – tyshock
    Feb 8, 2014 at 15:28
  • @tyshock I'll blog about this soon. Meanwhile, check my other answer (sharepoint.stackexchange.com/a/90081/8642). I haven't elaborated in details, but it will give you a hint of a possible usage of databound controls
    – MdMazzotti
    Feb 10, 2014 at 19:02
0

You can use inline code in master pages and in application pages by default.

Additionally, you can use inline code in site pages if you set up a PageParserPath exclusion rule.

From Inline Code:

Inline code is disabled by default on any customized or uploaded Web page in a SharePoint site. It can be enabled on a per directory path basis, with children potentially inheriting the settings. This exclusion can be enabled through the specific Web site path that is included in the PageParserPaths collection in the web.config file. After the PageParserPath inline code exclusion is set, any page within that directory has the capability to execute any code that is embedded directly in the HTML content of the page if the script tag is set to run at the server.

4
  • I didn't know it could be used in master pages. So you're saying that if I edit a master page in SPD, then there I can use inline code?
    – MdMazzotti
    Jan 22, 2014 at 19:08
  • Had a second read at the documentation. They state clearly: however, as soon as it is customized, the inline code will fail. So, I don't think that inline code can be inserted in customized master pages from SPD.
    – MdMazzotti
    Jan 22, 2014 at 19:11
  • I don't know about from SPD. I have used inline code in master pages in VS (as well as the Repeater control). Also, the documentation is advising against using inline code in a site definition, because editing the file in SPD causes ghosting, which is the issue there. "One problem with using inline code in a site definition is that the code will work inline as long as the page instance in a site is not customized to the file system. However, as soon as it is customized, the inline code will fail." Jan 22, 2014 at 19:20
  • I don't know only because I've never tried it. Personally, I don't use SPD. Jan 22, 2014 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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