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.
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 <%# %>
<%# %>
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>
<asp:PlaceHolder runat="server"><%= System.DateTime.Now.Year.ToString() %></asp:PlaceHolder>
I can't get the <%# %> to work (nothing's there in the html output), but the placeholder solution from Jim works.
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.
Please, sign in to be able to submit a new answer.