通过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
浙公网安备 33010602011771号