Question about use of RadCodeBlock

2 posts, 1 answers
  1. Boris
    Boris avatar
    289 posts
    Member since:
    Oct 2012

    Posted 10 Dec 2012 Link to this post

    I have a Dot Net 4.0 web app with quite a few of those <% %> tags scattered throughout the scripts of various pages.  Most pages have at least a little JavaScript, mostly routine stuff like custom validator handlers for dropdowns.  

    Today I got an exception: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

    This was fixed by placing the script block on that page in a RadCodeBlock.

    I've been looking at this documentation:

    It occurs to me that this RadCodeBlock is only the second one I've added to the entire project.  I've not had problems with other pages.

    In general would you say that it's good coding practice to routinely enclose all JavaScript blocks in RadCodeBlocks?
  2. Answer
    Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 13 Dec 2012 Link to this post

    Hi Boris,

    Yes, it is best practise to wrap all the JavaScript into RadCodeBlock control in order to avoid the mentioned error. Also please note that the RadCodeBlock should be used not only in case Javascript is added but for every server tag you have placed in the page markup.

    Maria Ilieva
    the Telerik team
    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 their blog feed now.
Back to Top