Customizing Web Parts - hiding prop in edit mode?

时光总嘲笑我的痴心妄想 提交于 2019-12-06 10:43:55

问题


Update:

private string _catalogIconImageUrl = "http://hostname/images/favicon.ico";

 [WebBrowsableAttribute(false),
    Category("HIDDEN"),
    Personalizable(PersonalizationScope.User),
    WebDisplayName("Catalog Icon Image url"),
    WebDescription("Something")]
    public string CatalogIconImageUrl
    {
        get
        {
            return _catalogIconImageUrl;
        }
        set
        {
            _catalogIconImageUrl = value;
        }
    }

with the above code, it does not show the image and also when i click on edit the webpart i still able to see the catalogIconImageUrl prop in edit mode

Update end

I've declared the property CatalogIconImageURL in the .Webpart file as follows:-

</property>    
<property name="CatalogIconImageUrl" type="string">images/company/companylogo.jpg</property>    //sample path...
</properties>

if I click on the Advanced Web Part Gallery as shown below in the screen shot, i able to see that property in editable so my question is, is there a way i can hide this property when user edit the web part? "Catalog Icon Image URL"


回答1:


You can set the WebBrowseable or Browseable attribute to false

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webbrowsableattribute.aspx

http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.browsable.aspx

Update:

It is also marked as virtual. This property is a OOTB property in WEb Part class. See here:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpart.catalogiconimageurl.aspx

You should override this property and then set the above attribute to false

     /// <summary>
            /// Catalog Icon
            /// </summary>
            [Category("Properties")]
            [DefaultValue("")]
            [Personalizable(PersonalizationScope.Shared)]
            [WebDisplayName("Catalog icon image URL:")]
            [WebDescription("Enter the WebPart title.")]
            [XmlElement(ElementName = "CatalogIconImageUrl")]
            [WebBrowsable(false)]
            public override string CatalogIconImageUrl
            {
}


来源:https://stackoverflow.com/questions/7252112/customizing-web-parts-hiding-prop-in-edit-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!