O'Reilly logo

Essential SharePoint by Jeff Webb

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Properties

The default web part template comes with a Text property. That property appears at the bottom of the property task pane in the Miscellaneous category if you display the web part page in a personal view and then select Modify My Web Part, as shown in Figure 9-11.

Displaying the custom Text property that comes with the web part template

Figure 9-11. Displaying the custom Text property that comes with the web part template

The provided Text property is really only intended as a basic starting point for your own properties. Starting from Text, the most common next steps are:

  1. Change the property storage from personal to Shared. Shared properties are available to everyone who views the page.

  2. Serialize the property so that changes in the task pane are reflected in the web part.

  3. Link the property setting to the value of a child control on the web part. That allows members to change the property and see the effects of the change.

  4. Save the property to the content database; otherwise, changes are lost when the member navigates away from the page.

The following code illustrates these changes by extending the template code to create a simple web part with a textbox and a Save button. The textbox is linked to the Text property, so if the member clicks Save, the property is preserved the next time the page is viewed:

 Private Const _defaultText As String = "" Dim _text As String = _defaultText   ' 1) Change storage to WebPartStorage(Storage.Shared). ' and ' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required