Skip to Main Content
Essential SharePoint
book

Essential SharePoint

by Jeff Webb
May 2005
Beginner content levelBeginner
336 pages
10h 14m
English
O'Reilly Media, Inc.
Content preview from Essential SharePoint

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 members:

  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. Render the child controls in the RenderWebPart event.

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

 ' 1) Declare child controls. Dim _txt As New TextBox Dim _br As New Literal Dim WithEvents _btn As New Button Dim _lbl As New Label Dim _total As String   Protected Overrides Sub CreateChildControls() ' Create utility object for dimensions. Dim u As Unit ' 2) Set child control properties. With _txt .Width = u.Pixel(400) .Height = u.Pixel(200) .TextMode = TextBoxMode.MultiLine End With With _br .Text = "<br>" End With With _btn .Width = u.Pixel(60) .Height = u.Pixel(30) .Text = "Sum" .ToolTip = "Click here to get total." End With With _lbl .Width = u.Pixel(100) .Height = u.Pixel(30) End With ' 3) Add the controls in the order to display them Controls.Add(_txt) Controls.Add(_br) Controls.Add(_btn) Controls.Add(_lbl) End Sub   ' Display web part. Protected Overrides Sub RenderWebPart _ (ByVal output As System.Web.UI.HtmlTextWriter) ' 4) Write controls to output stream. RenderChildren(output) End ...
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

SharePoint User's Guide

SharePoint User's Guide

Infusion Development Corp. (Infusion Development Corporation)
Beginning SharePoint® 2010: Building Business Solutions with SharePoint

Beginning SharePoint® 2010: Building Business Solutions with SharePoint

Amanda Perran, Shane Perran, Jennifer Mason, Laura Rogers

Publisher Resources

ISBN: 0596008805Errata Page