动态创建“WEB用户控件(WEB User Control)"和控件
2007-10-07 21:25
344 查看
用户控件有设计方便,界面可视化等优点,但是通常我们创建之后都是直接拖到页面中使用的,能不能在页面加载时动态创建呢?答案是肯定的:
请看如下代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!IsPostBack)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.Form.Controls.Add(LoadControl("~/Controls/CopyRight.ascx")); //就是这里
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TextBox txt = new TextBox(); //这里是创建一个ASP.net控件。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.Form.Controls.Add(txt);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
请看如下代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!IsPostBack)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.Form.Controls.Add(LoadControl("~/Controls/CopyRight.ascx")); //就是这里
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TextBox txt = new TextBox(); //这里是创建一个ASP.net控件。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.Form.Controls.Add(txt);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
相关文章推荐
- 动态创建“WEB用户控件(WEB User Control)”又一方法,及如何调用Web用户控件的方法,如何对控件用户控件中的控件
- 总结Asp.net中Page加载PostData的具体过程 进而解决"获取动态创建的控件的PostData数据"问题
- 动态创建DropDownList并实现互动和跳转的web用户控件
- C#.net中web工程中创建用户控件和被调用的方法
- 基于asp.net的web页面动态控件创建以及使用
- 基于ASP.NET的Web动态控件创建
- 无法创建Web项目"WebApplication1
- 基于ASP.NET的Web动态控件创建
- 线程间操作无效: 从不是创建控件" XX" 的线程访问它
- 基于ASP.NET的Web动态控件创建
- ASP.NET创建WEB用户控件
- 在.net2.0下动态创建用户控件(ascx)
- 动态创建的Web控件代码转为Html代码
- Web页面设计时提示"创建控件出错,未将对象引用设置到对象的实例”的错误解决办法
- WEB窗体用户控件的变量问题(动态)
- Vs2010设计ASP.NET页面时出现"创建控件时出错"
- 动态增加和删除多个web用户控件
- 玩转Web之Jsp(一)-----jsp中的静态包含(<%@include file="url"%>)与动态包含(<jsp:include>)
- 【转】C#线程间操作无效: 从不是创建控件" XX" 的线程访问它
- 关于开发高手2004第8期中,<jsp创建基于WEB的动态图表>一文中的些许错误