尝试添加ajax TabContainer时,出现错误“由于控件包含代码块(即<%...%>),因此无法修改Controls集合”。 [英] Trying to add ajax TabContainer, getting error "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)."

查看:111
本文介绍了尝试添加ajax TabContainer时,出现错误“由于控件包含代码块(即<%...%>),因此无法修改Controls集合”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网页上添加ajax:TabContainer。我没有任何构建错误,但是当我尝试浏览该页面时,它给了我错误:控件集合无法修改,因为控件包含代码块(即<%...%>)。 。

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. <% ... %>).".

我为示例站点重新下载了Ajax Control Toolkit,在VS中打开了解决方案,为TabContainer运行了示例,并且运行良好。我认为这可能是Ajax Control Toolkit的不同版本-但不是。这两个站点引用的AjaxControlToolkit.dll文件是相同的。为什么我不能让TabContainer在我的网站上工作?

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?

还有一个问题,但是我不知道它是否相关。我刚刚安装了Visual Studio2008。打开网站后,VS会在工具箱中自动创建选项卡 AJAX控件,并在其中填充所有ajax控件。在源代码中,所有控件都以 ajax为前缀-即< ajax:TabContainer runat = server ...>。

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" ... >".

当我打开示例网站时,Visual Studio在工具箱中创建了另一个选项卡- AjaxControlToolkit组件,其中充满了与 AJAX控件中相同的控件。我不知道为什么要两次添加相同的控件(但奇怪的是,在工具箱中为它们添加了不同的图标)。在源代码中,所有控件都以 ajaxToolkit为前缀-即< ajaxToolkit:TabContainer runat = server ...>。这里发生了什么?我只想让该死的TabContainer在我的网站上工作。

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.

推荐答案

您不能使用<%=%>(写)在使用标准服务器呈现的控件内阻塞-您会收到此错误。

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

要使ASP AJAX组件正常工作,您需要:

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

<head runat="server">...

否则,它也因该错误而崩溃。

Otherwise it crashes with this error too.

但是您可以在以下服务器控件中进行 databind

However you can databind inside these server controls:

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

然后在页面加载中:

Page.Header.DataBind();

由于ASP WebForms将控件呈现为组件集合的方式而发生错误-它们可以处理任何一个集合(并期望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.

永久避免此问题的最佳方法是切换到ASP MVC。

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

这篇关于尝试添加ajax TabContainer时,出现错误“由于控件包含代码块(即&lt;%...%&gt;),因此无法修改Controls集合”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆