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

Adding Child Controls

The UserInfoTable web part isn't interactive—the information flows only from the server to the browser. To make a web part that can interact with users:

  1. Declare the web controls to display in the web part.

  2. Override the CreateChildControls event to set control properties.

  3. Add each control to the controls collection.

  4. Set the ChildControlsCreated property to render to controls,

    or

    Render the child controls in the RenderWebPart method.

The following code demonstrates these steps to create a Sum web part containing a text box to input a series of numbers, a command button to perform the calculation, and a label to display the result:

 [Guid("6D9B7DBA-C365-4d18-A453-86102CCEA61A")] public class Sum : System.Web.UI.WebControls.WebParts.WebPart { // 1) Declare child controls. TextBox _txt = new TextBox( ); Literal _br = new Literal( ); Button _btn = new Button( ); Label _lbl = new Label( ); protected override void CreateChildControls( ) { // 2) Set child control properties. _txt.Width = Unit.Pixel(300); _txt.Height = Unit.Pixel(150); _txt.TextMode = TextBoxMode.MultiLine; _txt.ToolTip = "Enter a series of numbers to add."; _br.Text = "<br>"; _btn.Width = Unit.Pixel(50); _btn.Height = Unit.Pixel(25); _btn.Text = "Sum"; _btn.ToolTip = "Click here to get total."; _lbl.Width = Unit.Pixel(100); _lbl.Height = Unit.Pixel(30); _lbl.Text = "Total: "; // 3) Add the controls in the order to display them Controls.Add(_txt); Controls.Add(_br); Controls.Add(_btn); Controls.Add(_lbl); // ...
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