当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET动态加载用户控件的实现方法

ASP.NET
Asp.Net 通用数据操作类 (附通用数据基类)
asp.net汉字转拼音和获取汉字首字母的代码
asp.net 多字段模糊查询代码
OpenCms 带分页的新闻列表
URLRewriter最简单入门介绍 URLRewriter相关资源
asp.net Repeater取得CheckBox选中的某行某个值
asp.net清空Cookie的两种方法
asp.net一些很酷很实用的.Net技巧
asp.net生成高质量缩略图通用函数(c#代码),支持多种生成方式
asp.net TripleDES加密、解密算法
Asp.net中防止用户多次登录的方法
asp.net Repeater取得CheckBox选中的某行某个值的c#写法
asp.net DataGridView导出到Excel的三个方法[亲测]
C#,winform,ShowDialog,子窗体向父窗体传值
asp.net学习中发现的比较完整的流程
ASP.net 页面被关闭后,服务器端是否仍然执行中?
asp.net Context.Handler 页面间传值方法
asp.net xml序列化与反序列化
asp.net实例代码protected override void Render(HtmlTextWriter writer)
asp.net(c#)捕捉搜索引擎蜘蛛和机器人

ASP.NET动态加载用户控件的实现方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 49 ::
收藏到网摘: n/a

动态加载用户控件的方法,用asp.net的朋友推荐 第一步:例如用户控件放在MyList.Ascx,然后其Control指令是:
复制代码 代码如下:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ViewComment.ascx.cs" Inherits="Control_ViewComment"%>

这时候已经有了Inherits,自带了ClassName就是其名称,如果没有,则必须创建ClassName属性。
假设其有公共属性ID。
第二步:在某一个ASPX文件需要动态加载的话首先使用
复制代码 代码如下:

<%@ Reference Control="MyList.Ascx" %>
<%@ Page Language="C#" CodeFile="GetAscx.aspx.cs" Inherits="AdEntity_GetAscx" %>
引用,这时候在代码页GetAscx.aspx.cs可以动态加载ASCX控件了:
Control_ViewComment ctrl = (Control_ViewComment)Page.LoadControl("~/Control/ViewComment.ascx");
ctrl.ID = Request["AdentityId"];
base.Controls.Add(ctrl);

另:
复制代码 代码如下:

<%@ Register Assembly="Business" Namespace="Business" TagPrefix="My" %>

完成。