| By Joe Stagner | Article Rating: |
|
| November 20, 2006 11:00 AM EST | Reads: |
19,885 |
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.
Published November 20, 2006 Reads 19,885
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By 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 11/19/06 05:03:11 PM EST | |||
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. |
||||
- Kindle 2 vs Nook
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Windows 7 – Microsoft’s First Step to the Cloud
- Cloud Expo and the End of Tech Recession
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Reality Check at the Cloud Computing Expo
- Visual Studio 2010 Is Cloud Friendly
- Fired SCO CEO Fires Back
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Best Practices
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Eval JavaScript in a Global Context
- Windows 7 – Microsoft’s First Step to the Cloud
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- Programmatically Posting Data to ASP .NET Web Applications






























