Skip to Main Content
Essential SharePoint 2007, 2nd Edition
book

Essential SharePoint 2007, 2nd Edition

by Jeff Webb
September 2007
Beginner content levelBeginner
448 pages
10h 2m
English
O'Reilly Media, Inc.
Content preview from Essential SharePoint 2007, 2nd Edition

Programming Rendered Web Parts

Web parts are made up of ASP.NET and HTML controls that are then sent to a web part page for display. The code for a web part is simply a class based on the WebPart class as shown here (my comments identify key parts):

using System;                             // Standard namespaces...
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;// The WebPart class lives here.
using System.Xml.Serialization;

using Microsoft.SharePoint;              // The old-style WebPart class lives here.
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace WebPart1
{
    [Guid("93909b28-3853-4510-b76e-a14878dcbdae")]  //Guid identifies the feature.
    public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
    {                     // ^ This is a new style (ASP.NET) web part!
        protected override void Render(HtmlTextWriter writer)
        {   // This method draws the web part.
            // TODO: add custom rendering code here.
            // writer.Write("Output HTML");
        }
    }
}

Table 11-3 summarizes the major programming tasks you need to perform to turn this basic code template into a useful web part. I also list the key members, clauses, attributes, and interfaces used to complete each task.

Table 11-3. Web part programming tasks

Task

Summary

Key members

Create user interface

Add controls to the Controls collection, then render those controls and additional HTML.

Controls

CreateChildControls

RenderControls

RenderControl

Render

Add JavaScript and HTML

Write code to import and modify HTML control ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft® Office SharePoint® Server 2007 Best Practices

Microsoft® Office SharePoint® Server 2007 Best Practices

Ben Curry, Bill English
SharePoint 2007: The Definitive Guide

SharePoint 2007: The Definitive Guide

James Pyles, Christopher M. Buechler, Bob Fox, Murray Gordon, Michael Lotter, Jason Medero, Nilesh Mehta, Joris Poelmans, Christopher Pragash, Piotr Prussak, Christopher J. Regan

Publisher Resources

ISBN: 9780596514075Errata Page