为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
MMMHUHU 2019-08-02 03:02:36
“无法修改控件集合,因为控件包含代码块”我试图创建一个简单的用户控件,这是一个滑块。当我向用户控件添加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和滑块扩展器添加到占位符中,我仍然会得到错误。有什么问题吗?
查看完整描述

3 回答

?
守候你守候我

TA贡献1802条经验 获得超10个赞

 

首先,使用<%#而不是<%=启动代码块:

<head id="head1" runat="server">
  <title>My Page</title>
  <link href="css/common.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="<%# ResolveUrl("~/javascript/leesUtils.js") %>"></script></head>

这会将代码块从Response.Wread代码块更改为绑定表达式。
<%# ... %>绑定表达式不是代码块,CLR不会抱怨。然后在母版页的代码中添加以下内容:

protected void Page_Load(object sender, EventArgs e){
  Page.Header.DataBind();    }




查看完整回答
反对 回复 2019-08-03
?
慕丝7291255

TA贡献1859条经验 获得超6个赞

将javascript放在div标记下。

<div runat="server"> //div tag must have runat server
  //Your Jave script code goes here....</div>

会成功的!


查看完整回答
反对 回复 2019-08-03
  • 3 回答
  • 0 关注
  • 253 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号