|
|
YOUR FEEDBACK
|
TOP MICROSOFT .NET LINKS Tools
Quickstart: Building User-Configurable ASP.NET Web Parts
Understanding ASP.NET Web Parts
By: Joe Stagner
Nov. 20, 2006 11:00 AM
Digg This!
Page 2 of 2
« previous page
Now, for each of the user interface artifacts in the control that we want to be configurable by the end user at runtime, we have to define a Boolean indicator in our control that can be used to decide whether the element should or shouldn't be displayed according to the user's choices. Each will look like this.
Protected _PropertyONE As Boolean = True The property is marked as Personalizable so that the state of the property will be automatically saved when the property is modified. The property is also marked as WebBrowsable so that it can be modified in a designer like our PropertyGridEditorPart. By default, the value of a property marked as Personalizable is saved to a Microsoft SQL Server 2005 Express database table located in your application root App_Data folder. You can modify the location where personalization data is saved by modifying your application's Web configuration file. For the right value to be associated with the right user, the ASP.NET Framework has to be able to identify the current user. You can use personalization with both Windows and Forms Authentication (Windows authentication is the default). When using Forms Authentication, the user must be authenticated before the user requests the page. Since ASP.NET 2.0 implements the "Provider Model" for membership, you can use any available membership provider. The WebDisplayName and WebDisplayDescription are automatically used in our WebPartEditor. The Boolean value of each property will be set according to the checkbox in the Web Part Properties editor. Having defined a WebBrowsable property for each of the user interface elements that we want to be configurable by the user, we can simply use those properties before the page loads to set the element's "Visible" property to whatever the user has chosen.
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e Now our basic Web Part is ready for use, so we can build a simple .ASPX container to test our Web Part. We'll need an .ASPX page with a WebPartManager, a WebPartZone, and an EditorZone. In Visual Studio's Solution Explorer we can just drag the .ASCX file of our control and drop it into the WebPartZone. Then from the WebParts toolbox we can drag a WebPartEditorZone control (see Figure 4) and drop it onto the EditorZone on our page. Note that the WebPartZone control exposes a rich set of properties that we can use to configure the visual aesthetics of the user experience. For example, in our demo application we've set properties to add color and borders to the default menus displayed when the user is configuring the Web Part. There is one more bit of functionality that we have to implement before we can run a little application. We need to provide the user with a way to switch in and out of the "Edit Mode." To do this we'll just include a button on our WebForm and wire up its Click Event Handler to set the DisplayMode property of our WePartManager appropriately.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As _ You're up and running with your first Web Part. This article is a quick start, but the ASP.NET Web Parts framework is a rich set of technologies. Now that you have a bit of Web Parts development under your belt you're ready to start exploring some more advanced development with it. Check out the quick start and video training at www.asp.net and begin developing .DLL-based Web Parts using alternate membership providers, adding a Web Parts Catalog and more. Page 2 of 2 « previous page
MICROSOFT .NET LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING NEWS FROM THE WIRES
|
|||||||||||||||||||||||||||||||||||