This is a migrated thread and some comments may be shown as answers.
If Statement - control contains code blocks
6 Answers 40 Views
This is a migrated thread and some comments may be shown as answers.
dlewis
Top achievements
Rank 1
dlewis asked on 29 Oct 2009, 07:49 PM

I've posted this to the forum as well, feel free to respond to either this or the forum

I'm getting The Controls collection cannot be modified because the control contains code blocks (i.e. <%

Our code contains the following
<% if displaythis = False %>
.
.
<%else%>
.
.
<%end if%>

I've tried  <%# If displaythis = False Then %>  but that doesn't work, it doesn't even
compile. I've googled this to death and I'm at a complete loss at this point.
Any help is greatly appreciated.

I can't use the 

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

<%If UseIcons = False Then %>

</telerik:RadCodeBlock>

bunch of code
.
.
.

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

<%End If %>

</telerik:RadCodeBlock>

6 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 30 Oct 2009, 07:49 AM
Hello dlewis,

When you use server-side code blocks, you need to wrap the entire logic inside a single RadCodeBlock instance to avoid the error you get. More information on this subject can be found in this topic from the RadAjax documentation.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
onkar
Top achievements
Rank 1
answered on 30 Nov 2009, 04:10 PM
its not working

I'm getting The Controls collection cannot be modified because the control contains code blocks (i.e. <%
Our code contains the following

<table width=80%>
<tr>
      <td CssClass="normal_text"  align="left">&nbsp;</td>
      <td align="left">CONTENT 2</td>
    </tr>.
<% if (Flag == False) {%>
<tr>
      <td CssClass="normal_text"  align="left">&nbsp;</td>
      <td align="left">CONTENT 1</td>
    </tr>
<%}else{%>
<tr>
      <td CssClass="normal_text"  align="left">&nbsp;</td>
      <td align="left">CONTENT 2</td>
    </tr>.
.
<%}%>
<tr>
      <td CssClass="normal_text"  align="left">&nbsp;</td>
      <td align="left">CONTENT 2</td>
    </tr>.
</table>

Thanks
Onkar

0
Princy
Top achievements
Rank 1
answered on 01 Dec 2009, 01:02 PM
Hello Onkar,

Try wrapping any server-code or client-code on your aspx page into a RadCodeBlock or RadScriptBlock control and see if it makes a difference as mentioned by Sebastian.

-Princy.
0
Tal
Top achievements
Rank 1
answered on 24 Aug 2013, 12:37 PM
Hi Princy,

I tried to do as you wrote but nevertheless it seems that still I am having the problem to use code within my radAjaxManager.

Error:
========

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).



Thank, 
Tal
0
Tal
Top achievements
Rank 1
answered on 24 Aug 2013, 12:38 PM
Hi Princy,

I tried to do as you wrote but nevertheless it seems that still I am having the problem to use code within my radAjaxManager.

Error:
========

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).


Any ideas how to help ?

Thanks, 
Tal
0
Pavlina
Telerik team
answered on 28 Aug 2013, 09:26 PM
Hello,

Can you please post a simple code-snippet that demonstrates the issue? We would like to investigate the behavior you depicted.

Regards,
Pavlina
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Ajax
Asked by
dlewis
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
onkar
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Tal
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or