无法修改Controls集合,因为控件包含代码块(即)。 [英] The Controls collection cannot be modified because the control contains code blocks (i.e. ).

查看:85
本文介绍了无法修改Controls集合,因为控件包含代码块(即)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个asp.net应用程序,其中一个页面正在上传文件。上传文件页面包含一个检查文件大小的javascipt。



Hi,

I have an asp.net application and one of the pages is uploading a file. The upload file page contains a javascipt that checks the file size.

<script type="text/javascript">
       function CheckFileSize(sender, args) {
           var file = document.getElementById("<%= FileUpload.ClientID %>");
             if (file.files[0].size > 2 * 1024 * 1024) {
                 args.IsValid = false;
                 return
             }
             args.IsValid = true;
         }
    </script>





它在视觉工作室工作正常,但是当我发布它时在IIS上,我只有上传文件页面才出现以下错误:



It is working fine on the visual studio but when I published it on the IIS, I got the following error only with the upload file page:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).







我尝试了很多解决方案('#'等于'= ',placeHolder在脚本周围,而脚本在体内而不是头部)提到的错误消失但javascript停止工作。



有谁知道如何快速解决问题?因为我现在必须部署系统。



非常感谢,

Missa




I tried many solutions ('#' istead of '=', placeHolder around the script, and the script inside the body instead of head) the mentioned error disappeared but the javascript stopped working.

Does anyone know how to solve the problem quickly? Because I have to deploy the system now.

Many thanks,
Missa

推荐答案

将javascript放在div标签下如



Place the javascript under div tag like

<div  runat="server">
<script type="text/javascript">
       function CheckFileSize(sender, args) {
           var file = document.getElementById("<%= FileUpload.ClientID %>");
             if (file.files[0].size > 2 * 1024 * 1024) {
                 args.IsValid = false;
                 return
             }
             args.IsValid = true;
         }
    </script>
</div>





这样可行。如果这也不起作用,那么在javascript中指定实际的客户端ID,例如:document.getElementById('contentplaceholder_clientid')



This will work. if this also don't work then specify the actual client id in the javascript eg: document.getElementById('contentplaceholder_clientid')


这篇关于无法修改Controls集合,因为控件包含代码块(即)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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