Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
1.1k views
in SharePoint Server by 40 47 56

I'm trying to create multiple custom property in Visual WebPart in SharePoint Server but when building the SharePoint solution I get this error "Duplicate 'WebBrowsable' attribute"

This is my code to create multiple Custom Properties in Visual WebPart

 [WebBrowsable(true),
   WebDisplayName("User Name"),
   WebDescription("Enter User Name"),
   Personalizable(PersonalizationScope.Shared),
   Category("Mail Settings")]

 [WebBrowsable(true),
   WebDisplayName("Email"),
   WebDescription("Enter Email"),
   Personalizable(PersonalizationScope.Shared),
   Category("Mail Settings")]
 
 public string userName{
   get;
   set;
 }

 public string email{
   get;
   set;
 }

What am I doing wrong?


1 Answer

1 like 0 dislike
by 163 204 403
selected by
 
Best answer

Adding multiple custom properties in Visual WebPart

First of all, you should be aware of the Custom WebPart Property block consists of two sections as below

[WebBrowsable(true),
  WebDisplayName("SMTP Server"),
  WebDescription("Enter SMTP Server"),
  Personalizable(PersonalizationScope.Shared),
  System.ComponentModel.Category("Mail Settings")
]

public string SMTPServer{
  get;
  set;
}

So to define multiple properties in Visual Webpart you have to repeat the full custom property block as per your count of custom property that you need to use as the following:

// First Property

[WebBrowsable(true),
  WebDisplayName("SMTP Server"),
  WebDescription("Enter SMTP Server"),
  Personalizable(PersonalizationScope.Shared),
  System.ComponentModel.Category("Mail Settings")
]

public string SMTPServer{
  get;
  set;
}


// Second Property

[WebBrowsable(true),
  WebDisplayName("SMTP Port"),
  WebDescription("Enter SMTP Port"),
  Personalizable(PersonalizationScope.Shared),
  System.ComponentModel.Category("Mail Settings")
]

public int SMTPPort{
  get;
  set;
}

For more details, Please check How to add Custom Property in Visual WebPart?

If you don’t ask, the answer is always NO!
...