If you tried to modify some properties of your web parts and save them from server code you probably noticed that there are some differences in the way this is handled in the SharePoint web parts namespace and in the ASP.NET web part namespace. Particularly if you are trying to save web part properties from code that is outside of the actual web part.
In SharePoint land the SPWebPartManager class has the SaveChanges(webpart) method, which allows us to save the properties of any web part on the page from any code location. However in the ASP.NET namespace this method is not available. Certainly one option is to switch to the SharePoint web parts namespace, however this is not recommended and prevents the web parts from being used in pure ASP.NET environment.
The only viable alternative I was able to find out is to expose the protected WebPart.SetPersonalizationDirty() in all my custom web parts:
1: public class CustomWebPart:WebPart
4: public void SaveProperties()
Then I can make changes to my web parts' properties and save them from other page events, such a Page_Load etc.
1: WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(Page);
3: CustomWebPart wp = wpm.WebParts as CustomWebPart;
4: wp.Title = "New name, new property";
Seemingly easy, but for some reason took my colleague and me tons of times to figure out.
I want to ask a question about webpart property.
I have a webpart, and I want to user personalize webpart property without using tool pane.
(property scope is user)
I can change this property value in run time, but I dont know how to personalize this changes ?
That is, the changes in runtime affect all users, not current user.
Do you have any idea?
Thanks in advance.
How do you declare the [Personalizable] attribute for your custom properties?
The default value is PersonalizationScope.Shared, so if you want to switch the personalization scope to User you need to declare them with:
Please help me with this.
I have decorated my public string property with the following attributes:
The purpose is to store some information specific to user only through code( therefore WebBrowsable is false).
However, i dont see the above property working. It always gets me the value stored by administrator and not the value stored by respective contributors.
Am i missing something? Thanks in advance