通过SharePoint 2010 WebPart部署用户控件

在VS 2010中通过可视化WebPart加载一个自定义控件的基本代码如下:

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace SimpleWebPart.VisualWebPart1
{
public class VisualWebPart1 : WebPart
{
protected const string _ascxPath = @”~/_CONTROLTEMPLATES/SimpleWebPart/VisualWebPart1/CustomUserControl.ascx”;
public VisualWebPart1()
{
}
protected override void CreateChildControls()
{
try
{
Control control = this.Page.LoadControl(_ascxPath);
Controls.Add(control);
}
finally
{
base.CreateChildControls();
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
}
}

参考资料

Deploy User Control with webpart SharePoint 2010

posted @ 2010-09-24 22:03  Sunmoonfire  阅读(689)  评论(0)    收藏  举报