解决“控件包含代码块,因此无法修改控件集合”问题的方法

在一个.aspx文件中添加下面的代码:

<%=EnabledFileType%>

出现错误提示:

System.Web.HttpException (0x80004005): 
控件包含代码块(即 <% ... %>),因此无法修改控件集合。
在 System.Web.UI.ControlCollection.Add(Control child)

对应的英文错误为:

The Controls collection cannot be modified because the control contains code blocks

解决方法:

改为如下的代码(等号改为井号):

<%#EnabledFileType%>

并在Page_Load中添加如下的代码:

private void Page_Load(object sender, System.EventArgs e)
{   
    this.DataBind();
}

搞定!

posted @ 2014-10-23 11:08  dudu  阅读(3684)  评论(1编辑  收藏  举报