)...">

Trying to add ajax TabContainer, getting error "The Controls collection cannot be modified because the control contains blocks of code (i.e. <% ...%>)".

I want to add ajax: TabContainer to my webpage. I don't get any build errors, but when I try to navigate to the page, it gives me an error: "The collection of controls cannot be modified because the control contains blocks of code (eg <% ...%>).".

I re-downloaded the Ajax Control Toolkit for the sample sites, opened the solution in VS, ran the sample for the TabContainer and it worked fine. I thought it might be a different version of the Ajax Control Toolkit, but no. The AjaxControlToolkit.dll files referenced by the two sites are identical. Why can't I get the TabContainer to work on my site?

There is another problem, but I don't know if it's related. I recently installed Visual Studio 2008. As soon as I opened my site, VS automatically created the "AJAX Controls" tab in the toolbar and populated it with all the ajax controls. In the source code, all controls are prefixed with "ajax" - that is, "<ajax: TabContainer runat =" server "...>".

However, when I opened the sample site, Visual Studio created another tab in the toolbar, AjaxControlToolkit Components, populated with all of the same controls as in AJAX Controls. I don't know why he added the same controls twice (but oddly enough with different icons for them in the toolbar). In the source code, all controls are prefixed with "ajaxToolkit" - i.e. "<ajaxToolkit: TabContainer runat =" server "...>". What's going on here? I just want the darn TabContainer to work on my site.

+1


source share


6 answers


You cannot use <% =%> (write) blocks inside a control that uses standard server rendering - you are getting this error.

For ASP AJAX components to work, you need:

<head runat="server">...

      

Otherwise it will crash with this error as well.

However, you can bind data inside these server controls:



<head runat="server">
    <link rel="stylesheet" type="text/css" 
        href="<%# ResolveUrl( "~/styles/common.aspx" ) %>" />
...

      

And then on the download page:

Page.Header.DataBind();

      

The error occurs because of the way ASP WebForms renders controls as collections of components - they can handle either a collection (and expect databind <% #) or a write literal (and expect <% =), but not both.

The best way to avoid this problem for good is to switch to ASP MVC.

+6


source


This error is not specific to Ajax.



You can try putting your ajax: TabContainer inside asp: Panel. Alternatively, remove the <% ...%> code blocks from your page.

+2


source


I understood that!

This is the error message you receive if you try to use AJAX controls while it <head>

contains a tag <script>

.

I just moved the JavaScript to the body and it works fine now.

+1


source


Hey guys, this is again not just javascript tags, but everything in the headers of your page that uses <% =%> or <% Response.Write%>. Either change your code to use databinding <% # eval ( some code )%> directive or move stuff to body (this is also useful for speeding up your pages load times).

+1


source


Pragnesh, Check between HEAD tags for any javascript. I had some javascript with <%%> codeblocks that was preventing AJAX controls from working.

0


source


no need to do anything, just hold <% = ....%> The part of the code that is on the main page in

-1


source







All Articles