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

G

Guest

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
 
G

Guest

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
 
G

Guest

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,
 
Joined
Feb 10, 2010
Messages
12
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top