我有一个网络用户控件:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SitewideNotification.ascx.cs" Inherits="Controls_Fresh_SitewideNotification" %>
<asp:PlaceHolder runat="server" ID="Javascript">
test
</asp:PlaceHolder>
在我背后的代码中,我有:
protected void Page_Load(object sender, EventArgs e)
{
Page.Master.FindControl("JSContent").Controls.Add(Javascript);
}
我的母版页以:
<asp:ContentPlaceHolder runat="server" ID="JSContent"/>
</form>
</body>
</html>
但我得到了错误:
System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Page.Master.FindControl("JSContent").Controls.Add(Javascript);
我有点迷茫这是为什么,有人知道如何解决吗?