11.1. Using Server Controls and User Controls as Web Parts


You want to take advantage of web part functionality while leveraging standard ASP.NET server controls or perhaps your existing user controls.


Use the ASP.NET 2.0 membership and web part features by implementing the membership features described in Recipe 9.5 and modify web.config to configure the web part provider. In the pages that use web parts, add a WebPartManager control, add one or more WebPartZone controls, add a CatalogZone control, and add the desired server controls and user controls to the CatalogZone.

Add a <webParts> element to web.config as follows:

		<personalization defaultProvider="AspNetSqlPersonalizationProvider">
				<remove name="AspNetSqlPersonalizationProvider"/>
				<add name="AspNetSqlPersonalizationProvider"
					applicationName="CH11ExamplesVB" />
				<deny users="*" verbs="enterSharedScope" />
				<allow users="*" verbs="modifyState" />

In the .aspx file for the pages that will use web parts:

  1. Add a WebPartManager control.

  2. Add one or more WebPartZone controls.

  3. Add a CatalogZone control along with PageCatalogPart and DeclarativeCatalogPart controls.

  4. Add the server controls and user controls you want to use as web parts to the DeclarativeCatalogPart control.

  5. Add a Customize button (or equivalent) to provide ...

Get ASP.NET 2.0 Cookbook, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.