If Statement - control contains code blocks

7 posts, 0 answers
  1. dlewis
    dlewis avatar
    13 posts
    Member since:
    Aug 2009

    Posted 29 Oct 2009 Link to this post

    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>

  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 30 Oct 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. onkar
    onkar avatar
    3 posts
    Member since:
    Jan 2009

    Posted 30 Nov 2009 Link to this post

    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

  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Dec 2009 Link to this post

    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.
  6. Tal
    Tal avatar
    22 posts
    Member since:
    May 2013

    Posted 24 Aug 2013 Link to this post

    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
  7. Tal
    Tal avatar
    22 posts
    Member since:
    May 2013

    Posted 24 Aug 2013 Link to this post

    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
  8. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 28 Aug 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017