SharePoint 2013具有自定义属性的可视Web部件

SharePoint 2013具有自定义属性的可视Web部件,sharepoint,web-parts,Sharepoint,Web Parts,已解决。继续阅读… 我可以从这个1:1复制代码,但它不起作用。 我在web部件属性中看不到任何自定义属性。 虽然没有“杂项”类别。只有外观、布局和高级 namespace Tts.CareersPortal.Web.CareersPortal.Fn.WebParts.NewContactTeaserWebPart { using System; using System.Collections.Generic; using System.ComponentModel;

已解决。继续阅读…

我可以从这个1:1复制代码,但它不起作用。 我在web部件属性中看不到任何自定义属性。 虽然没有“杂项”类别。只有外观、布局和高级

namespace Tts.CareersPortal.Web.CareersPortal.Fn.WebParts.NewContactTeaserWebPart
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls.WebParts;
    using MyNameSpace.NewContactTeaserWebPart;

    public partial class NewContactTeaserWebPartUserControl : UserControl
    {
        private int _contactTeaserCount;

        [Category("Extended Settings"),
        Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Sample Text"),
        WebDescription("Please Enter a Sample Text")]
        public int ContactTeaserTeaserCount
        {
            get
            {
                return _contactTeaserCount;
            }
            set
            {
                _contactTeaserCount = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            IEnumerable<MyContact> contacts = LoadContactProperties();

            Repeater1.DataSource = contacts;
            Repeater1.DataBind();
        }

        private IEnumerable<MyContact> LoadContactProperties()
        {
            ContactFinder contactFinder = new ContactFinder(ContactTeaserTeaserCount);

            IEnumerable<MyContact> result = contactFinder.GetContact();
            return result;
        }
    }
}
命名空间Tts.CareersPortal.Web.CareersPortal.Fn.WebParts.newContactStraterWebPart
{
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用System.Web.UI;
使用System.Web.UI.WebControl.WebParts;
使用MyNameSpace.NewContactStraterWebPart;
公共部分类NewContactStraterWebPartUserControl:UserControl
{
私人国际联系账户;
[类别(“扩展设置”),
Personalizable(PersonalizationScope.Shared),
WebBrowsable(正确),
WebDisplayName(“示例文本”),
WebDescription(“请输入示例文本”)]
公共int联系人计数
{
得到
{
返回_contactstriercount;
}
设置
{
_ContactStratesrCount=值;
}
}
受保护的无效页面加载(对象发送方、事件参数e)
{
IEnumerable contacts=LoadContactProperties();
Repeater1.DataSource=联系人;
Repeater1.DataBind();
}
私有IEnumerable LoadContactProperties()
{
ContactFinder ContactFinder=新的ContactFinder(ContactStraterTereAserCount);
IEnumerable结果=contactFinder.GetContact();
返回结果;
}
}
}
解决方案:我将web部件属性添加到错误的类文件中:-/您必须将其添加到web部件,而不是用户控件。要将Web部件属性传递给用户控件,我建议采用以下方法-其他方法也可以


不起作用。有什么想法吗?

如果您在使用C#在SharePoint 2010中创建可视化Web部件时需要帮助,请遵循

如果仅需要有关webpart属性的帮助,请尝试以下代码:

public static string SampleText;
[Category("Extended Settings"),
Personalizable(PersonalizationScope.Shared),
WebBrowsable(true),
WebDisplayName("Sample Text"),
WebDescription("Please Enter a Sample Text")]
public string _SampleText
{
    get { return SampleText; }
    set
    {
        // Sample Validation
        Regex oRegEx = new Regex("[a-zA-Z]+");
        if (!oRegEx.IsMatch(value))
            throw new Microsoft.SharePoint.WebPartPages.
                WebPartPageUserException(
                "Please enter alphabeth characters only");
        SampleText = value;
    }
}
同样,您也会发现以下文章对您有所帮助: WebBrowsable(true),使其在Web部件属性中可见。
这一个Personalizable(PersonalizationScope.Shared)定义了它在什么模式下(共享或个性化)可见。

Argh!-代码项目链接帮助了我们。我将属性添加到错误的类文件:<尽管我不能推荐codeproject文章。静态字段和PersonalizationScope。用户听起来不是个好主意。我更喜欢。