in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

kwanl's blog

Using custom web part properties with WPSC

Web Part Page Services Component (WPSC) is a feature of SharePoint that lets you interact with your web parts through client-side script.

While working on a recent web part, I wanted to access the a custom property using WPSC but was getting errors when trying to save it. It turned out that the problem was that my custom properties weren't being serialized to Xml because it was the holding the default value after being initialized.

From the 2003 SDK:

[...] do not use the DefaultValue attribute if you want properties to be accessible through the Web Part Page Services Component (WPSC). If it exists and a property is set to the default, the property won’t appear in the WPSC Properties collection. In this case, provide a ShouldSerializeXXX method for your property.

If you have both DefaultValue attribute and define a ShouldSerializeXXX method, the DefaultValue attribute's effect overrides the ShouldSerialeXXX method.

There are a lot of interesting things you can do if you can access your web part through client-side script. And SharePoint provides an infrastructure for this but I haven't seen many web parts that take advantage of it. Think AJAX.

Comments

No Comments

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts