13.07.2015 Views

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

370CHAPTER 10 ■ SHAREPOINT WEB PARTSus<strong>in</strong>g the Controls.Add method. You can also utilize event handlers for the ASP.NET controls,which will be necessary to capture button clicks and the like. List<strong>in</strong>g 10-3 shows several controlsbe<strong>in</strong>g added to a web part.List<strong>in</strong>g 10-3. Add<strong>in</strong>g ASP.NET Controls to a Web PartProtected txtDisplay As New TextBoxProtected WithEvents btnGo As New ButtonProtected Overrides Sub CreateChildControls()Me.Controls.Add(btnGo)txtDisplay.Width = Unit.Percentage(100)Me.Controls.Add(txtDisplay)End SubPrivate Sub btnGo_Click( _ByVal sender As Object, ByVal e As System.EventArgs) _Handles btnGo.ClicktxtDisplay.Text = "Button clicked!"End SubOnce the controls are all configured and added to the web part, you are ready to draw theoutput. When render<strong>in</strong>g the user <strong>in</strong>terface of the web part, you use the HtmlTextWriter classprovided by the RenderContents method. This class allows you to create any manner of HTMLoutput for the web part.As a general rule, you should render your user <strong>in</strong>terface with<strong>in</strong> an HTML . The reasonfor this is that you can never be sure what the web part page layout will look like. As yousaw <strong>in</strong> Chapter 5, layouts and web part zones can take almost any form. Therefore, you shoulduse the relative layout offered by the tag to respect the width def<strong>in</strong>ed by the zonewhere the web part appears. List<strong>in</strong>g 10-4 shows how to render a table conta<strong>in</strong><strong>in</strong>g ASP.NETcontrols. You should take particular note of the width def<strong>in</strong>ition with<strong>in</strong> the table.■Note Style sheet purists may prefer to use a style class to control the layout of a web part. While you cancerta<strong>in</strong>ly reference style sheet classes from a web part, <strong>SharePo<strong>in</strong>t</strong> makes extensive use of layout tables, so Ido not see much of an issue with us<strong>in</strong>g them <strong>in</strong> your web parts.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!