2

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>
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;
            }    
        }

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.