You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

解决Ajax AsyncFileUpload引发的Controls集合无法修改错误

问题:The Controls collection cannot be modified 错误排查(AsyncFileUpload控件引发)

问题概述

遇到「The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)」错误,经排查确认是Ajax AsyncFileUpload控件导致——移除该控件后错误消失。其他页面运行正常,说明母版页本身无问题。

已尝试的无效方案

  • 将代码块包裹在<asp:PlaceHolder Runat="server">中
  • 确保母版页无<%= %>代码块
  • 将所有JS文件引用包裹在PlaceHolder中
  • 在母版页后台添加Page.Header.DataBind()

母版页相关代码

<asp:PlaceHolder runat="server">
    <script src='<%# ResolveUrl("path_to_script") %>'
    ...
</asp:PlaceHolder>

<link rel="stylesheet" href="~/assets/css/whatever.css" />

完整错误信息

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +11686804
AjaxControlToolkit.ToolkitResourceManager.RegisterCssReferences(Control control) +893
System.Web.UI.Control.LoadRecursive() +90
System.Web.UI.Control.LoadRecursive() +185
System.Web.UI.Control.LoadRecursive() +185
System.Web.UI.Control.LoadRecursive() +185
System.Web.UI.Control.LoadRecursive() +185
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1602

引发问题的控件代码

<ajaxToolkit:AsyncFileUpload runat="server" ID="fuDBData"
    ClientIDMode="Static"
    class="hidden"
    ThrobberID="myThrobber"
    UploaderStyle="Traditional"
    OnUploadedComplete="fuDBData_UploadedComplete"
    OnUploadedFileError="UploadedFileError"
    onClientUploadStart="uploadStart"
    OnClientUploadComplete="uploadComplete" />

内容的提问来源于stack exchange,提问作者NoBullMan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 11:42:04