Sharepoint Web Parts

Page 579 of Addison Wesley Sharepoint 2010 Development in VS 2010

Web parts are ASP.NET server side controls that run in the context of a web part page and allow users to edit and modify the controls in the browser. A web part page is an ASP.NET page that has web part zones defined that serve as placeholders for the web parts to be added.

Each web part page has a web part manager object that tracks which web parts have been added to each particular zone, and stores and retrieves data about how each web part has been customized and personalized. A SharePoint web part page does not use the ASP.NET WebPartManager and WebPartZones
classes directly—instead it uses its own classes called SPWebPartManager and SPWebPartZone, which inherit from the corresponding ASP.NET classes.

Sharepoint 2010 supports two types of web parts:

(1) ASP.NET 2.0 Web Part, which derived from System.Web.UI.WebControls.WebParts.Web Part (NEWER)

(2) Older style SharePoint web parts, which derive from Microsoft.SharePoint.WebPartPages.WebPart (OLDER)

When to use Older style web paet?
(1) create cross-page web part connection
(2) connections bwteen web parts that are outside of web part zones

(3) take advantage of Sharepoint data-caching


————————————————————————————–
Create a visual web part in VS 2010

Create a new project in VS 2010, using Visual Web Part as template, called CreateTaskWebPart. Only option is Farm project.

Visual Web Part uses user control, which must be deployed to the ~/_CONTROLTEMPLATES folder in the SharePoint hive. In order to access this folder, the web part needs to have farm permissions.

Add controls to the web part.

Switch to code view, add using Microsoft.Sharepoint
to the top. Because we use Sharepoint server Model to access the list.

Enter code:

Deploy it and add it to your web page:

Now implement a partial page update. Add a label next to the button, lblResult.

Switch to the source view, and add these tags to include all existing code:

Update the code :

Web part Customization

To customize the web Part Edit pane:

For example, we want to add a custom property call “site collection URL”, so we can add the task to that site collection, then add these to the *.cs file:

Deployed again and you will see the new field:

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: