Trying to add ajax TabContainer, getting error “Th

2019-08-06 08:51发布

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

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 was perhaps a different version of the Ajax Control Toolkit - but no. The AjaxControlToolkit.dll files being referenced by the two sites are identical. Why can't I get the TabContainer to work on my site?

There is one more issue, but I don't know whether it's related. I just recently installed Visual Studio 2008. As soon as I opened my website, VS automatically created the tab "AJAX Controls" in the toolbox and filled it with all the ajax controls. In the source code, all controls are prefixed with "ajax" - i.e., "< ajax:TabContainer runat="server" ... >".

However, when I opened the sample website, Visual studio created another tab in the toolbox - "AjaxControlToolkit Components", filled with all the same controls as in "AJAX Controls". I don't know why it added the same controls twice (but, strangely enough, with different icons for them in the toolbox). 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.

6条回答
甜甜的少女心
2楼-- · 2019-08-06 09:29

no need to do any thing just keep <%=....%> Part of code which is having in Master page in

查看更多
混吃等死
3楼-- · 2019-08-06 09:30

Hey guys, it's again not just javascript tags, but anything within the head tags of your page that uses <%= %> or <% Response.Write %>. Either change your code to use the databinding directive <%# eval(some code) %> or move the stuff to the body (this is also useful for speeding up the loading time of your pages).

查看更多
干净又极端
4楼-- · 2019-08-06 09:35

Pragnesh, Check between the HEAD tags for any javascript. I had some javascript with the <%%> code-blocks that prevented the AJAX tab controls from working.

查看更多
Explosion°爆炸
5楼-- · 2019-08-06 09:40

This error is not specific to Ajax.

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

查看更多
萌系小妹纸
6楼-- · 2019-08-06 09:48

You can't use <%= %> (write) blocks inside a control that uses the standard server rendering - you get this error.

In order for the ASP AJAX components to work you need:

<head runat="server">...

Otherwise it crashes with this error too.

However you can databind inside these server controls:

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

And then in your page load:

Page.Header.DataBind();

The error occurs due to the way ASP WebForms render controls as component collections - they can handle either the collection (and expect databind <%#) or literal writes (and expect <%=) but not both together.

The best way to avoid this issue permanently is to switch to ASP MVC.

查看更多
混吃等死
7楼-- · 2019-08-06 09:48

I've figured it out!

This is the error message you get if you attempt to use AJAX controls while your <head> contains a <script> tag.

I just moved the JavaScript into the body, and it seems to work fine now.

查看更多
登录 后发表回答