【问题标题】:Create SharePoint 2013 web part that loads user controls创建加载用户控件的 SharePoint 2013 Web 部件
【发布时间】:2017-05-24 03:40:08
【问题描述】:

我需要创建一个将用户控件加载到其中的 Web 部件。 我找到的所有答案要么已过时,要么不起作用。

我正在使用 Visual Studio 2015 和 SharePoint 2013。 我用我的用户控件和其他的 Web 部件创建了一个项目,但我不知道如何链接它们...

有什么帮助吗? 谢谢

【问题讨论】:

    标签: c# visual-studio-2015 user-controls sharepoint-2013 web-parts


    【解决方案1】:

    如果您的 webpart 不是 Visual webpart,您可以像这样加载用户控件(在 webpart cs 文件中):

    namespace ProjectName.Folder.Custom_Webpart
    {
        [ToolboxItemAttribute(false)]
        public class Custom_Webpart : System.Web.UI.WebControls.WebParts.WebPart
        {
            private const string _ascxPath = @"~/_CONTROLTEMPLATES/15/ProjectName/Folder/Custom_UserControl.ascx";
    
            protected override void CreateChildControls()
            {
                var control = Page.LoadControl(_ascxPath) as Custom_UserControl;
                //this.ChromeType = PartChromeType.None;
                Controls.Add(control);
            }
        }
    }
    

    如果您的 Web 部件是可视 Web 部件,您可以加载用户控件,在您的 Web 部件 .ascx 文件中插入以下说明:

    <%@ Register Src="/_controltemplates/15/ProjectName/Folder/Custom_UserControl.ascx" TagPrefix="Custom" TagName="CustomControl" %>
    
    <Custom:CustomControl runat="server" />
    

    【讨论】:

    猜你喜欢
    • 2012-12-24
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 2016-05-13
    • 2016-06-09
    • 2014-05-31
    相关资源
    最近更新 更多