1

I've created a Sharepoint 2010 Visual Webpart in Visual Studio 2012. The structure of the template that it generates is slightly different than in VS 2010. Previously, it would create the Webpart class and a user control. In 2012 that is all combined into a single class file.

However, I've yet to be successfully add any properties to the webpart. It deploys and compiles. But properties aren't showing up in the user interface when you edit the webpart. I've defined it as below:

private string _myString;
    [Category("Custom Properties")]
    [DefaultValue("test123")]
    [Browsable(true)]
    [WebPartStorage(Storage.Personal)]
    [FriendlyNameAttribute("Custom String")]
    [Description("Type a string value.")]
    [XmlElement(ElementName = "MyString1231123")]
    public string MyString
    {
        get
        {
            return _myString;
        }
        set
        {
            _myString = value;
        }
    }

Any issues?

I did notice that the template that vs2012 generates uses a System.Web.UI.WebControls.WebPArts.Webpart based class, not a sharepoint one.

0

try this:

private string _myString;

[Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
WebDisplayName("MyString1231123"),
WebDescription("Type a string value.")]
public string MyString
{
    get
    {
        return _myString;
    }
    set
    {
        _myString = value;
    }
}

in 2012 settings are slightly different :)

http://msdn.microsoft.com/en-gb/library/vstudio/ee231551(v=vs.110).aspx

0

You have to declare the Personalizable type [Personalizable(PersonalizationScope.Shared)] or [Personalizable(PersonalizationScope.User)]

So your WebPart property would look like this:

    [WebBrowsable(true)]
    [Personalizable(PersonalizationScope.Shared)]
    [WebDisplayName("My string")]
    [Description("This is my string")]
    [Category("My own Category")]
    public string MyString { get; set; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.