O'Reilly logo

ASP.NET 2.0 Cookbook, 2nd Edition by Geoffrey T. LeBlond, Michael A Kittel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.1. Using Server Controls and User Controls as Web Parts

Problem

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

Solution

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:

	<webParts>
		<personalization defaultProvider="AspNetSqlPersonalizationProvider">
			<providers>
				<remove name="AspNetSqlPersonalizationProvider"/>
				<add name="AspNetSqlPersonalizationProvider"
					type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
					connectionStringName="sqlConnectionString"
					applicationName="CH11ExamplesVB" />
			</providers>
			<authorization>
				<deny users="*" verbs="enterSharedScope" />
				<allow users="*" verbs="modifyState" />
			</authorization>
		</personalization>
	</webParts>

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required