English 中文(简体)
不能修改管制的收集,因为控制含有密码区块。
原标题:The Controls collection cannot be modified because the control contains code blocks

This is a bit different to all the other questions as they all seem to refer to the head content specifically. With this one, I have a user control with the following placeholder:

<asp:PlaceHolder runat="server" ID="DiscussIncludes">    
    <script>
        var OnLastPage = <asp:Literal runat="server" ID="OnLastPageJS" />;
        var AJAXWait = false;
        var MinChars = <%=Settings.MinimumCommentChars%>;
        var AJAXURL = "<%=ResolveClientUrl("~/Handlers/DiscussAjaxHandler.ashx")%>";
        var CurrUsername = "<%=ThisUser.Username %>";
        var GravHash = "<asp:Literal runat="server" ID="GravJSRef" />";
        var RelURL = "<%=ResolveClientUrl("~/users/")%>";
        var Anch = "<%=Anchor.ToString()%>";
        var MyRep = "<%=MyRepString%>";
        var CurrReportID = 0;
        var LastPageURL = "<asp:Literal runat="server" ID="JSLastPageURL" />";
        var AllowedChars = <%=Settings.MaxCommentChars %>;
    </script>
    <script src="<%=CommonFunctions.AllocateStaticPath("/js/Discuss.js?v=" + Settings.JSVersionID)%>"></script>
    <script src="<%=CommonFunctions.AllocateStaticPath("/js/BlockUI.js?v=" + Settings.JSVersionID)%>"></script> 
</asp:PlaceHolder>

在我后面的法典中:

ContentPlaceHolder FooterControl = (ContentPlaceHolder)Page.Master.FindControl("JavascriptIncludes");
FooterControl.Controls.Add(DiscussIncludes);

这一错误:

不能修改控制收集,因为控制含有密码区块(即:%......>);

。 Add(DiscussIncludes);。 I ve Trial changing all the <%= to <%# within the place holder but no luck.

值得注意的是,这一控制在我的所有其他网页上都做了罚款。 造成这种情况的想法是什么?

问题回答

这种控制没有造成问题——如果在你把控制权附加给特定环境时发生,而且只在这种环境中出现问题。 申诉网页上还有什么?

我在我的系统上尝试了以下工作,似乎在发挥作用。

<asp:PlaceHolder runat="server" ID="DiscussIncludes">    
    <script type="text/javascript">
        var path = <%=Common.path%>;
    </script>
    <script type="text/javascript" src= <%=Common.GetScriptPath("jquery-1.4.1-vsdoc.js")%> ></script>
    <asp:PlaceHolder runat="server" ID="JsIncludes"> 
    </asp:PlaceHolder>
</asp:PlaceHolder>

准则。

    LiteralControl include = new LiteralControl(string.Format("<script src= {0} ></script>", Common.GetScriptPath("jquery-1.4.1.min.js")));
JsIncludes.Controls.Add(include);

I get the exception if i try to add the control to DiscussIncludes. However if add the control to JsIncludes it works. JsIncludes control is a child placeholder of DiscussIncludes.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签