Personalizable()/WebBrowsable() issues in custom Web Part

Discussion in 'ASP .Net' started by =?Utf-8?B?TWFyYyBXb29sZnNvbg==?=, Jun 14, 2007.

  1. Hi,

    I think this is a relatively simple problem, but it's starting to annoy me
    quite a bit. I have two issues with a custom Web Part that I have created,
    both related to property editing at run time using an EditorZone.

    One of my web parts contains a control which displays information for a
    particular (default) user. The user should have the ability to select an
    alternate user whose information should be displayed in the control, and so I
    have defined the relevant property as follows on the custom Web Part:

    [Personalizable(true), WebBrowsable(true), WebDisplayName("Scope code")]
    public string ScopeCode
    {
    get
    {
    return pr_scopeCode;
    }
    set
    {
    pr_scopeCode = value;
    }
    }

    where pr_scopeCode is a private local variable.

    To give the user a nicer front end than just a box for the code, I have
    written a custom EditorPart to enable the users to be displayed and selected
    from a drop-down list. *Problem 1*: although the drop-down list displays
    correctly at run time, the value chosen by the user is not saved back to the
    page. I can post the code for the custom EditorPart if that would be of
    assistance.

    I also have some other properties that I wish to allow the user to modify,
    including the Title of the web part (I do not wish to open up all the
    properties available in the AppearanceEditorZone). To implement this I have
    used the code below:

    [Browsable(true), Personalizable(), WebBrowsable(),
    WebDisplayName("Title")]
    public override string Title
    {
    get
    {
    return base.Title;
    }
    set
    {
    base.Title = value;
    }
    }

    *Problem 2*: this, and the many other properties that I have marked as
    'WebBrowsable' are not displayed in the EditorZone at run time at all.

    Please can anyone suggest why these WebBrowsable properties would not be
    available for editing at run time, and/or why changes in the custom
    EditorPart are not saved back as personalised data? If I use the
    AppearanceEditorZone or other pre-defined EditorZones, changes may be made
    and saved back against the user successfully.

    Thanks,

    Marc
     
    =?Utf-8?B?TWFyYyBXb29sZnNvbg==?=, Jun 14, 2007
    #1
    1. Advertising

  2. Having done a bit more investigation I can see that *Problem 2* is actually
    working correctly (rookie error - please don't ask) but *Problem 1* still
    exists, seemingly only for static web parts. If I use the Catalog to add
    another one of my custom web parts I am able to make the selection from the
    drop-down list in the custom EditorZone, and it _is_ saved back to the web
    part successfully. To resolve this, I removed the WebBrowsable attribute from
    the ScopeCode property, as the 'old' value in the PropertyGridEditor was
    overwriting the 'new' one selected from the custom Editor.

    For the static web part, the value now seems to be saved and the contents of
    the webpart updated as required when in *EditDesignMode*, but is _lost_ when
    returning to BrowseDesignMode.

    Any ideas? I would rather avoid adding all existing static web parts
    dynamically in code.

    Thanks,

    Marc
     
    =?Utf-8?B?TWFyYyBXb29sZnNvbg==?=, Jun 14, 2007
    #2
    1. Advertising

  3. Could I ask about the rookie error? I must be doing the same because I just
    can't see any of my custom properties.

    Thanks,

    "Marc Woolfson" wrote:

    > Having done a bit more investigation I can see that *Problem 2* is actually
    > working correctly (rookie error - please don't ask) but *Problem 1* still
    > exists, seemingly only for static web parts. If I use the Catalog to add
    > another one of my custom web parts I am able to make the selection from the
    > drop-down list in the custom EditorZone, and it _is_ saved back to the web
    > part successfully. To resolve this, I removed the WebBrowsable attribute from
    > the ScopeCode property, as the 'old' value in the PropertyGridEditor was
    > overwriting the 'new' one selected from the custom Editor.
    >
    > For the static web part, the value now seems to be saved and the contents of
    > the webpart updated as required when in *EditDesignMode*, but is _lost_ when
    > returning to BrowseDesignMode.
    >
    > Any ideas? I would rather avoid adding all existing static web parts
    > dynamically in code.
    >
    > Thanks,
    >
    > Marc
     
    =?Utf-8?B?R0JlbHppbGU=?=, Aug 15, 2007
    #3
  4. Ok it really was a rookie error... my properties were not public.


    "GBelzile" wrote:

    > Could I ask about the rookie error? I must be doing the same because I just
    > can't see any of my custom properties.
    >
    > Thanks,
    >
    > "Marc Woolfson" wrote:
    >
    > > Having done a bit more investigation I can see that *Problem 2* is actually
    > > working correctly (rookie error - please don't ask) but *Problem 1* still
    > > exists, seemingly only for static web parts. If I use the Catalog to add
    > > another one of my custom web parts I am able to make the selection from the
    > > drop-down list in the custom EditorZone, and it _is_ saved back to the web
    > > part successfully. To resolve this, I removed the WebBrowsable attribute from
    > > the ScopeCode property, as the 'old' value in the PropertyGridEditor was
    > > overwriting the 'new' one selected from the custom Editor.
    > >
    > > For the static web part, the value now seems to be saved and the contents of
    > > the webpart updated as required when in *EditDesignMode*, but is _lost_ when
    > > returning to BrowseDesignMode.
    > >
    > > Any ideas? I would rather avoid adding all existing static web parts
    > > dynamically in code.
    > >
    > > Thanks,
    > >
    > > Marc
     
    =?Utf-8?B?R0JlbHppbGU=?=, Aug 15, 2007
    #4
  5. =?Utf-8?B?TWFyYyBXb29sZnNvbg==?=

    eliza81

    Joined:
    Feb 10, 2010
    Messages:
    12
    Create custom property in a web part as a dropdown list

    SharePoint allows you to create custom web parts to help you provide highly customized solutions to your clients/users. The properties of these web parts are added by default but to further customize the solution, you can also create custom properties. The following example demonstrates how to add a custom dropdown property to a custom webpart.
    // Create a Enum for Languages

    public enum LanguageByEnum

    {
    English = 0,
    French,
    Spanish
    };

    Thanks
    Eliza
    Sharepoint migration india
     
    eliza81, Jun 22, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve R

    Web Custom Control Part 2

    Steve R, Oct 24, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,885
    William Robertson
    Oct 27, 2003
  2. Joerg Jooss

    Re: Web part versus Custom controls

    Joerg Jooss, Feb 26, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,890
    Joerg Jooss
    Feb 26, 2006
  3. Handle
    Replies:
    0
    Views:
    536
    Handle
    Jan 29, 2008
  4. Handle

    [Personalizable(PersonalizationScope.User)]

    Handle, Jan 29, 2008, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    125
    Handle
    Jan 29, 2008
  5. Jack
    Replies:
    8
    Views:
    283
Loading...

Share This Page