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
980 views
in SharePoint Server by 39 45 53

I have created a new Visual WebPart with custom webpart property that deployed successfully, but when adding the Visual WebPart to my Page and editing its properties, I noted that the custom webpart property is not shown

custom wepart property is not shown in edit webpart

It's my code to add a custom property in Visual WebPart

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace WPs.ContactForm {

  public partial class ContactFormUserControl: UserControl {

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

    ]
    public string username {
      get;
      set;
    }

  }
}

How I can show a custom property in Visual WebPart?


1 Answer

1 like 0 dislike
by 158 184 367
selected by
 
Best answer

Why Custom Property is not shown in Visual WebPart?

This behavior occurs in case you are using Visual WebPart (Farm Solution Only) that inherits from UserControl, not from System.Web.UI.WebControls.WebParts.WebPart.

Custom property is not shown in Visual WebPart

So, in your case, to get your custom property shown and working as expected, you have to add your custom property in the webpart.cs file that contains a partial class that inherits from System.Web.UI.WebControls.WebParts.WebPart, NOT in the UserControl.ascx.cs file.

custom property is not working in visual webpart

Otherwise, you have to use Visual WebPart (Sandbox). but it may not satisfy your requirements and has many limitations.

Visal web part with custom property in SharePoint

For more details about how you can use Custom Property in Visual WebPart (Farm Solution Only), Please check How to Create Custom Web Part Property in SharePoint Visual WebPart

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