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. Linux上ssh免秘钥互登

    两台机器分别为:master:192.168.1.10sever1:192.168.1.20 1.检查机器名和连通性 a.查看/etc/hostname [root@master master]# m ...

  2. 第十篇.6、python并发编程之IO模型

    一 IO模型介绍 为了更好地了解IO模型,我们需要事先回顾下:同步.异步.阻塞.非阻塞 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非 ...

  3. 网络初级篇之STP(概念原理)

    一.什么是STP 生成树协议(Spanning Tree Protocol,STP),是一种工作在OSI网络模型中的第二层(数据链路层)的通信协议,基本应用是防止交换机冗余链路产生的环路.用于确保以太 ...

  4. c++ easyX的学习

    画象棋盘来浅显学习了解easyx 了解象棋盘的构成: 如图就为一个基本的象棋棋盘我们下面就用esayx来画出这个棋盘,我的感觉这个棋盘大概分为两个部分:第一部分就是棋盘的大致布局,第二个就是棋盘的细节 ...

  5. hdu4405 概率dp

    飞行棋游戏 问从0结束游戏的投色子次数期望是多少 设dp[i]表示i到n的期望,那么可以得到dp[i]=(dp[i+1]+dp[i+2]+dp[i+3]+dp[i+4]+dp[i+5]+dp[i+6] ...

  6. Codeforces 837D - Round Subset DP

    先算出每个数的pop1(twonum),pop(fivenum)然后DP ans[i][j]表示选i个数有j个2时最多有多少个5 转移方程是 ;j--) { ;w++) { ans[j][w]=max ...

  7. 第二章 Vue快速入门-- 18 v-for中key的使用注意事项

    注意:如果属性和方法还没定义直接使用的话,就会报   xxx is not defined 导致界面不能正常显示.我看视频教程里老师的可以直接使用,而且界面正常显示,可能是vue版本不同吗?还不清楚 ...

  8. 高性能mysql 第5章 创建高可用的索引

    b-tree索引 一定程度上说,mysql只有b-tree索引.他没有bitmap索引.还有一个叫hash索引的,只在Memory存储引擎中才有. b-tree索引跟oracle中的大同小异. mys ...

  9. 本地安装sass出错问题解析

    2016年3月23日个人博客文章--迁移到segmentfault 安装sass ruby安装因为sass依赖于ruby环境,所以装sass之前先确认装了ruby.先导官网下载个ruby 在安装的时候 ...

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

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