1
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Problem reported by Traci Dukes - 3/19/2019 at 1:56 PM
Not A Problem
I am unable to use the controls in our webforms .net 4.7.2 version and get the error below.
Has anyone else experienced this?

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

2 Replies

Reply to Thread
0
Daniel Guerriero Replied
You cannot use code blocks inside a server control. You should assign those properties in the code behind class.


0
Cem Alacayir Replied
Employee Post
Yes when you have a WebForms control (with Runat="Server" attribute), you can't put <% ... %> code blocks inside that control tag. This is how ASP.NET WebForms markup (aspx) works. If you are trying to set GleamTech control's properties you can do it from code behind, e.g.

protected void Page_Load(object sender, EventArgs e)
{
    documentViewer.Document = "...";
}
If you are trying to insert something inside <head runat="server"> tag, then you can do this:

<head runat="server">
     <asp:literal ID="someLiteral" run="server" />
</head>
and then in code-behind you can set it like this:

protected void Page_Load(object sender, EventArgs e)
{
    someLiteral.Text = "...";
}

Reply to Thread