September 2007
Beginner
448 pages
10h 2m
English
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 |
|
Add JavaScript and HTML | Write code to import and modify HTML control ... |