Question

im trying to set a DefaultValue for my custom webpart property..

namespace Beraterprofil.VisualWebPart1
{
    [ToolboxItemAttribute(false)]
    public class VisualWebPart1 : WebPart
    {
        private string _sectionToRead = "CV";

        [WebBrowsable(true), Category("Miscellaneous"), Personalizable(PersonalizationScope.Shared),
            WebDisplayName("Welche Sektion soll gelesen werden?"), DefaultValue("CV")]
         public string sectionToRead
         {
             get { return _sectionToRead; }
             set { _sectionToRead = value; }            
         }

This is how i programmed it so far. What really confuses me is when i'm debugging this my sectionToRead string always displays "SPS-Section-ContactInfo" and i can't figure out from where he gets this string value..

Display of the Debug

Was it helpful?

Solution

AFAIK, DefaultValue attribute won't work for webpart properties.

You can use .webpart file for setting default values to your properties. You will need to add new <property> element under <properties> tag, like following:

<property name="sectionToRead" type="string">CV</property>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top