YOUR FEEDBACK
DataCore and Egenera Combination Delivers Next Generation Server and Storage Virtualization
Virtualization news for the channel community and you ! wrote: Trackback A...

SYS-CON.TV
TOP MICROSOFT .NET LINKS


Quickstart: Building User-Configurable ASP.NET Web Parts
Understanding ASP.NET Web Parts

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
    <Personalizable(PersonalizationScope.User), WebBrowsable(), _
    WebDisplayName("Show The First Thing"), _
    WebDescription("Use this property to show/hide Thing ONE")> _
    Public Property PropertyONE() As Boolean
      Get
        Return _PropertyONE
      End Get
      Set(ByVal value As Boolean)
        _PropertyONE = value
      End Set
    End Property

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
    As System.EventArgs) Handles Me.PreRender
       TextBox1.Visible = PropertyONE
       TextBox2.Visible = PropertyTWO
       TextBox3.Visible = PropertyTHREE
    End Sub

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 _
System.EventArgs) Handles Button1.Click
    If Not WebPartManager1.DisplayMode Is _
WebPartManager.EditDisplayMode Then

       WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode
       Button1.Text = "Set Edit Mode Off"
    Else
       WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode
       Button1.Text = "Set Edit Mode On"
    End If
End Sub

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

About Joe Stagner
Joe Stagner joined Microsoft in 2001 as a technical evangelist and is now a Developer Community Champion with the Microsoft MSDN Team. Joe?s technical career began at age 14 with a part-time job as a robotics control programmer, and has visited virtually every genre of technical vocation from Device Driver Developer to President and CEO of a publicly traded New York City consulting firm. Joe?s development experiences have allowed him to create commercial software applications across a wide diversity of technical platforms, from Mainframes through UNIX and Linux, to Microsoft technologies on the Intel and Mobile computing platforms. While Joe is generally interested in all computing technology, in recent years he has been particularly focused on highly performant, geoscalable Web application architectures, multiplatform interoperability, and writing secure code. www.JoeOn.NET

.NET News Desk wrote: For more than 20 years the software development industry has regarded reuse as the Holy Grail of software development. Programming language-based object-oriented features promised to deliver the significant benefits of increased productivity and cost-effectiveness by creating reusable objects, but in industry-wide practice OO itself hasn't delivered the results we hoped for.
read & respond »
MICROSOFT .NET LATEST STORIES
Desktop Virtualization Market to be Worth at Least $1.8b by 2012 Up From Nothing
Pushing back against VMware, its chief rival, Tuesday, Citrix released its ballyhooed, on-demand XenDesktop, the widgetry that delivers custom, managed virtual Windows desktops from a data center server to a user over the network, and priced the stuff. Theres a free Express Edition for
Xenocode Introduces New Application Virtualization Technology
Xenocode launched its flagship offering, Xenocode Virtual Application Studio. Xenocode Virtual Application Studio is a next-generation application virtualization environment that allows Windows, .NET and Java-based desktop applications to be deployed in standalone executables that run
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
AJAX World - Deploying an ASP.NET AJAX RSS Reader on Linux
Have you ever wished you could run ASP.NET applications on Linux, without having to rewrite your code or leave the Visual Studio development environment? In this article, I show you how to port Steve Clements' AJAX ASP.NET RSS Reader to native Java and deploy it to Apache Tomcat on Lin
Citrix and Microsoft Unveil New Branch Office Application Delivery Solution
Citrix and Microsoft announced the availability of Citrix Branch Repeater , an innovative new line of branch office appliances developed and marketed as part of a strategic alliance between the two companies. By staging the delivery of applications and Windows services closer to branch
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING NEWS FROM THE WIRES
Juniper Gaining Ground Among Networking Pros as an Exciting Vendor -- New Research From TheInfoPro
TheInfoPro (TIP), an independent research network and leading supplier of market intelligence