https://stackoverflow.com/questions/5508666/dynamically-add-html-to-asp-net-page

https://stackoverflow.com/questions/4975823/adding-to-page-control-collection-from-inside-a-user-control

在page上添加多个相同的file upload control(自定义的控件),现在想要在添加自定义控件的同时,注入一段HTML

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

 

Usercontrol doesn't have a PreInit event, but nothing's stopping you from adding a handler to the Page PreInit event in your UserControl:

Page.PreInit += new EventHandler(Page_PreInit);

edit - you're right - you can't capture PreInit from a usercontrol, though I'm surprised you can't - but you can still change the page controls collection by adding code to the constructor of the UserControl. I tried this and it works.

public MyUsercontrol()
{
Page page = (Page)HttpContext.Current.Handler;
Literal lit = new Literal();
lit.Text="text";
page.Controls.Add(lit);
}

Adding an event handler to Page.PreInit in the constructor compiles but it never fires.

(end edit)

That said, I'm not exactly sure why this is necessary to achieve your goal. Why don't you just have your dialog control render it's own div in-line wherever you drop it into the form, and use that as the parent, instead of trying to create one somewhere else in the form? I can't think of why it would be important for it to physically be rendered at the beginning or end of the form. It's a dialog so it will always be invisible until you use it, right?

The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.的更多相关文章

  1. 错误:The Controls collection cannot be modified because the control contains code blocks (i.e. ). .

    用 <%# %>这种写法是写在数据绑定控件中的,之所以用 <%= %>会出现The Controls collection cannot be modified because ...

  2. C#错误:The Controls collection cannot be modified

    用 <%# %>这种写法是写在数据绑定控件中的,之所以用 <%= %>会出现The Controls collection cannot be modified because ...

  3. The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    刚才Insus.NET有尝试改一段代码,是让用户能动态变更网页背景图片的小功能.当Insus.NET去执行铵钮Click事件时,它却出现标题的错误.代码是这样的: 此代码,原本是没有什么问题的,但现在 ...

  4. System.Web.UI.Page的页面基类

    服务器端的page类 所有我们编写的页面都继承自page类,可见page类是非常重要的,page类提供了哪些功能,直接决定了我们的页面类可以继承什么功能,或者说,直接决定了我们的页面类功能的强大与否! ...

  5. 继承System.Web.UI.Page的页面基类

    服务器端的page类      所有我们编写的页面都继承自page类,可见page类是非常重要的,page类提供了哪些功能,直接决定了我们的页面类可以继承什么功能,或者说,直接决定了我们的页面类功能的 ...

  6. asp.net c# 网上搜集面试题目大全(附答案)

    1.String str=new String("a")和String str = "a"有什么区别? String str = "a"; ...

  7. [转]asp.net c# 网上搜集面试题目(附答案)

    本文转自:http://www.cnblogs.com/hndy/articles/2234188.html 1.String str=new String("a")和String ...

  8. ASP.net 页面生命周期

    ASP.NET 页面生命周期 Page_Preinit(); 在页初始化开始时发生 Page_Init(); 在所有控件初始化且应用外观设置后引发 Page_InitComplete(); 在页初始化 ...

  9. C# 问题解决思路--《数组bytes未定义》,ASP.NET页面加载顺序

    好久没写博客了,废话不多说,直接说问题. 问题发生情况,首先这个是老项目,然后我是第一次修改.当我解决了各种引用,数据库配置之后等类似的问题,我启动的项目的时候,无任何问题,但是当我点击页面的按钮的时 ...

随机推荐

  1. 100、神器的 routing mesh (Swarm07)

    参考https://www.cnblogs.com/CloudMan6/p/7930321.html   上一节我们提到了 swarm 的 routing mesh .当外部访问任意节点的8080端口 ...

  2. Spring的基本应用(1):IDEA版本

    一.Spring概述: 1.什么是Spring? Spring是分层的JavaSE/EE应用full-stack(一站式)轻量级开源框架,以IoC(Inverse Of Control:控制反转)和A ...

  3. Eclipse中插件的运用

    1. hotcode2.jar 支持java代码热部署,改了本地java代码不需要重新部署生效,可以节省开发时间,提高开发效率. 安装方法: 到help -- install new software ...

  4. concurrent.futures:线程池,让你更加高效、并发的处理任务

    并发任务池 concurrent.futures模块提供了使用工作线程或进程池运行任务的接口. 线程池和进程池的API是一致的,所以应用只需要做最小的修改就可以在线程和进程之间进行切换 这个模块提供了 ...

  5. 华为ensp问题:云映射本地网卡,直连路由器可以ping通,pc却不行?

    拓扑图:cloud 云映射本机物理网卡:192.168.56.1     R1可以Ping通,所有Pc都不行,路由表也存在路由信息,不知道什么问题?

  6. windows时钟服务设置

    运行Regedit,打开注册表编辑器. 找到注册表项HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\,将Anno ...

  7. 认识配置文件schema.xml(managed-schema)

    1.schema文件是在SolrConfig中的架构工厂定义,有两种定义模式: 1.1.默认的托管模式: solr默认使用的就是托管模式.也就是当在solrconfig.xml文件中没有显式声明< ...

  8. 关于LRU算法(转载)

      原文地址: http://flychao88.iteye.com/blog/1977653 http://blog.csdn.net/cjfeii/article/details/47259519 ...

  9. Kendo UI for jQuery自定义小部件第一弹!不得不看的入门指南

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  10. Vue打包上线之后CSS没有压缩和不生效

    前言 当用vue-cli 脚手架 打包压缩时,发现打包出来的css 没有被压缩, 所以查阅了些资料,下面用这个方法解决: 1.首先注释掉webpack.prod.conf.js中下面的代码 new O ...