All about the Strategy, Design, Customisation, Deployment and Development of SharePoint and its related Technologies

  Administration   All Me!! Baby!!   BDC   Book Review   Business   CKS   Conferences   CQWP   Development   Duffer Moments   Email   Errors   Family   Fixes   General   Groove   How To   How To Code   InfoPath   iPhone   IRM   Longhorn   Lotus Notes   Migration   Mobility   Office System 2007   Personal Projects   Powershell   Records Management   Search Server   Security   SharePoint   SharePoint 2010   Silverlight   SQL   Tech Ed 2008   Testing   Vista   VSTO   WSS   XSL

[07/12/2007] MOSS2007 – Web part Properties (Part 3)
 
Categories: Development, SharePoint, Office System 2007
 

In my last couple of posts we have looked at exposing web part properties in different ways. So far we have looked at using standard "WebBrowsable" properties and "Custom Tool Parts". In this quick post we will look at creating an "EditorPart" instead. "Editor Parts" are simply another way to expose properties and create the user interface that is rendered within the "Modify Shared Web Part" task pane. So let's begin, to begin with let's create a new class for our project:

In this example I am going to call it "DemoWebPartEditorPart". Once added if you look at the base code it should look as shown below:

At the moment the code is not ready for creating the "EditorPart". The following changes need to be made:

The key here is to add a reference to "System.Web.UI.WebControls.WebParts", once this is done you can then base your class on the "EditorPart" class. As in the last post the bulk of the code will remain the same.

The same controls will be added and we will; use the same method as before, by adding each control to a row method and adding each row to the table object.

We will also then call the "CreateChildControls" function to render all the controls within the main panel.

Now we have the same code as before, let's look at what extras we need to add to make this an "EditorPart". The "EditorPart" class just like the "ToolPart" class requires that you override the "SyncChanges" and "ApplyChanges" methods within your class. In this example the code would look similar to this:

In this code we are simply calling the parent and syncing the values between the two. Realistically we can do anything we wish in this code block. Now we have the above methods completed, we need to go back to our main web part class and add the following code:

This code loops through the "EditorPartCollection" and adds our new "EditorPart". Notice also that we are assigning it an ID, using a custom function I created.

The create GUID method simply using the following code:

When we put all of the code together we end up with the following when the web part is put into "Edit" mode:

As you can see the process is the same for using "ToolPart" and "EditorParts". Each allows for better design interfaces and management. Yes they are slightly more complicated but worth it in the end.

 
0 Comments
 

Comments

Name:

URL:

Email:

Comments: