Use <%= %> In Layout

Brenden Kehren asked on May 29, 2014 19:05

Not sure why this happens (only in Kentico I should say) but when I try to do something as simple as

<%=DateTime.Now.ToString("dddd")%>

It works perfect for roughly 20-30 minutes then it errors out stating

There was an error processing the page. The error can be caused by the configuration of some component on the master page. Check the master page configuration or see event log for more details. Original message: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Whats the problem? It works fine in any other asp.net app just not Kentico.

Correct Answer

Brenden Kehren answered on May 29, 2014 20:01

Learned something today after I looked back at previous projects, I've been doing this in my master page in previous projects, this particular project I'm doing this a page. Forgot all about this so now things work when I use the standard <%# %>

2 votesVote for this answer Unmark Correct answer

Recent Answers


Jim Spillane answered on May 29, 2014 20:17

That is a strange one that does not occur on every site. We ended up using a PlaceHolder on the masterpage... <asp:PlaceHolder runat="server"><%= System.DateTime.Now.Year.ToString() %></asp:PlaceHolder>

3 votesVote for this answer Mark as a Correct answer

Marcel Guldemond answered on October 28, 2015 20:52

I can't get the <%# %> to work (nothing's there in the html output), but the placeholder solution from Jim works.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 29, 2015 08:44

Hi,

Using the code blocks is not supported since the correct life cycle cannot be ensured in all cases. I would recommend to use this workaround instead.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.