【转】用LoadControl的方式来加载Webpart
原文链接:http://blog.sina.com.cn/s/blog_4925e2f901000ati.html
-
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
-
public class WebpartDemo1 : System.Web.UI.WebControls.WebParts.WebPart, INamingContainer
-
Control _innerUserControl = new Control();
protected override void Render(HtmlTextWriter writer)
{
this.EnsureChildControls();
_innerUserControl.RenderControl(writer);
}protected override void CreateChildControls()
{
try
{
_innerUserControl = this.Page.LoadControl("/bin/WebpartDemo.ascx");this.Controls.Add(_innerUserControl);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}}
此时在我们的项目的bin目录中就有两个文件(.dll,.pdb)
<SafeControl Assembly="WebpartDemo" Namespace="WebpartDemo" TypeName="*" Safe="True" />
把 <trust level="WSS_Custom" originUrl="" />
修改为 <trust level="Full" originUrl="" />
使MOSS有权限访问bin目录中的ascx.
5.修改网站设定
- "网站动作/网站设定"
- 添加部件
"组件库/网页组件"
选定后,单击"扩展组件库"保存.
6.导入到页面测试
This posting is provided "AS IS" with no warranties, and confers no rights.
浙公网安备 33010602011771号