请问“无法修改控件集合,因为控件包含代码块”

“无法修改控件集合,因为控件包含代码块”

我试图创建一个简单的用户控件,这是一个滑块。当我向用户控件添加AjaxToolkit SliderExtender时,我得到以下内容(*&$#()@#Error):

    Server Error in '/' Application. The Controls collection cannot be modified because the control contains code blocks (i.e. ``). Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. ``).

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. ``).]    System.Web.UI.ControlCollection.Add(Control child) +8677431    AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ExtenderBase\ScriptObjectBuilder.cs:293 AjaxControlToolkit.ExtenderControlBase.OnLoad(EventArgs e) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:306 System.Web.UI.Control.LoadRecursive()
    +50    System.Web.UI.Control.LoadRecursive()
    +141    System.Web.UI.Control.LoadRecursive()
    +141    System.Web.UI.Control.LoadRecursive()
    +141    System.Web.UI.Control.LoadRecursive()             
    +141    System.Web.UI.Control.LoadRecursive()
    +141    System.Web.UI.Control.LoadRecursive()
    +141    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


    Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074

我已经尝试在用户控件中放置一个占位符,并以编程的方式将TextBox和滑块扩展器添加到占位符中,我仍然会得到错误。


有什么问题吗?


MMMHUHU
浏览 254回答 3
3回答

守候你守候我

&nbsp;首先,使用<%#而不是<%=启动代码块:<head&nbsp;id="head1"&nbsp;runat="server"> &nbsp;&nbsp;<title>My&nbsp;Page</title> &nbsp;&nbsp;<link&nbsp;href="css/common.css"&nbsp;rel="stylesheet"&nbsp;type="text/css"&nbsp;/> &nbsp;&nbsp;<script&nbsp;type="text/javascript"&nbsp;src="<%#&nbsp;ResolveUrl("~/javascript/leesUtils.js")&nbsp;%>"></script></head>这会将代码块从Response.Wread代码块更改为绑定表达式。自<%# ... %>绑定表达式不是代码块,CLR不会抱怨。然后在母版页的代码中添加以下内容:protected&nbsp;void&nbsp;Page_Load(object&nbsp;sender,&nbsp;EventArgs&nbsp;e){ &nbsp;&nbsp;Page.Header.DataBind();&nbsp;&nbsp;&nbsp;&nbsp;}

慕丝7291255

将javascript放在div标记下。<div&nbsp;runat="server">&nbsp;//div&nbsp;tag&nbsp;must&nbsp;have&nbsp;runat&nbsp;server &nbsp;&nbsp;//Your&nbsp;Jave&nbsp;script&nbsp;code&nbsp;goes&nbsp;here....</div>会成功的!
打开App,查看更多内容
随时随地看视频慕课网APP