Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've created a new web part in a sandbox solution. This web part has a custom string property called 'PetName'.

I'd expect to be able to set the initial value of this property in the .webpart file. While this works perfectly in a Farm solution, in a Sandbox solution it does not. The field shows in the web part properties on the UI, but it is blank. I am able to persist a value if I enter a value into the field and click OK.

Does anyone have any idea how to manage this? I'm stumped.

Thanks, Dave

DumbWebPart.cs:

namespace MyDumbWebPart.DumbWebPart
{
    [ToolboxItemAttribute(false)]
    public class DumbWebPart : WebPart
    {
        [WebBrowsable(true), Personalizable(PersonalizationScope.Shared)]
        public string PetName
        {
            get;
            set;
        }

        protected override void CreateChildControls()
        {
        }
    }
}

DumbWebPart.webpart

<?xml version="1.0" encoding="utf-8"?>
<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="MyDumbWebPart.DumbWebPart.DumbWebPart, $SharePoint.Project.AssemblyFullName$" />
      <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="Title" type="string">MyDumbWebPart - DumbWebPart</property>
        <property name="Description" type="string">My Web Part</property>
        <property name="PetName" type="string">Fluffy</property>
      </properties>
    </data>
  </webPart>
</webParts>
share|improve this question

1 Answer 1

Use get;set; as shown below sample:

private static string OverLayText="<b>This is an html</b>";
        [Category("Extended Settings"),
        Personalizable(),
        WebBrowsable(),
        WebDisplayName("OverLay text"),
        WebDescription("OverLay Text")]
        public string _OverLayText
        {
            get
            {
                return OverLayText;
            }
            set
            {
                OverLayText = value;
            }    
        }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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