Designing with WebParts in Visual Web Developer | ||
John Mueller
January 16, 2005 |
|
|
| ||
One of the new features in Visual Studio .NET is Visual Web Developer, a special application that helps you create entire Web sites. Visual Web Developer makes your Web applications look amazingly similar to their desktop counterparts, and those Web applications can provide more flexibility. It's easy to take a look at this new feature, by downloading the preview of Visual Web Developer Express. ADVERTISEMENTWebParts are only a small part of the total product, but they're exciting because they allow your users to completely customize the Web pages you've created for them. For example, let's say your Web application needs to display various kinds of company data. Instead of grabbing everything-or-nothing, you can customize what is shown and how it's accomplished. If the user doesn't care to see a list of employees on the department page, he can remove it from the Web page. The information still exists on the server, but the user doesn't have to bother with it. If he wants that list back again, later on, he can use the tools you include in your Web application to re-add it. The user can also move items around and customize the Web page in other ways. Intriguing? I'll show you how to use this very neat capability as you build Web-based programs. It's a Trick, Right? WebParts rely on a combination of server-side and client-side code. When you create a Web page that includes WebParts, the server automatically generates scripts based on the content of the page you design. The server side of the code manages the page and, in a local database, stores any changes the user makes. Note: While this technique eliminates the need for cookies, it also creates a requirement for a strong privacy policy that users will accept. (The user identification and selections are both encrypted in a way that makes it very difficult to decipher any particular user's preferences.) WebParts may be the best thing to hit the development community in
recent history, and it doesn't even require a lot of code. Visual Web
Developer does most of the coding in the background. You use design
view to show the IDE how the page should look, set properties to tell
it how you want the page to act, and let the IDE generate most of the
code for you. In fact, it's possible to create simple customizable
pages that require no coding at all on your part. The only element
necessary is the Adding the Before you do anything else, add a This control doesn't actually create any content, and you don't have to do anything to configure it. However, you must have one (and only one) of these controls on the page before you add any other WebPart controls to the page. You can drag and drop this control from the Toolbox or add it to the page in Source view, as shown here. <asp:WebPartManager ID="WebPartManager1" Runat="server"> Changing Selections with the WebPartPageMenu WebParts provide a lot of flexibility, but that flexibility is only
available when you allow the user to make changes. Before the user can
make changes, you must add a This menu provides a list of selections or verbs which the user may use to make changes to the page. The <asp:WebPartPageMenu ID="WebPartPageMenu1" Notice that this control has four verbs configured:
Once you have the Creating Content with the WebPartZone A WebPart Web page contains two kinds of content:
Normally, you'll include several WebPartZone controls on a page, so the user can move items around. A page might contain a sidebar for less important information, a main area for important materials, and a lower section for items the user wants, but doesn't use very often. The point of this example is to show the WebPart technology, rather than interesting content, so the two WebPartZone controls shown here contain simple labels and hyperlinks. You can create all of this content in Design view. However, it's interesting to look at the code that the IDE generates automatically for you as you design your page. Here's an example of some of the content you could create. <asp:WebPartZone ID="wpzTest" The The content controls (labels and hyperlinks, here) appear within a <ZoneTemplate> tag. You must include this tag as a container for the content. The content itself is relatively simple, and you can include any content you want within the <ZoneTemplate> tag. Simply adding several of these controls lets a user move content
around. To allow other actions, you must provide the requisite zones.
For example, to allow a user to delete content, you provide a Modifying the Content with an Depending on what you want the user to do with the page, you can provide design and edit verbs on the When you include the edit verb, you also need to add an <asp:EditorZone ID="EditorZone1" Runat="server"> As with most zone controls, you must place the Figure 1: Make changes to the appearance (AppearanceEditorPart) and layout (LayoutEditorPart) of the Web page. To make this display appear, the user first chooses Edit from the Change the Layout
menu. This selection displays the various controls, as shown in Figure
1, and makes the Edit selection for each control accessible. Choosing
the Edit option for a particular control displays both the You can add other controls to the list. The Adding New Items with the CatalogZone In this context, a catalog isn't a list of acquirable items. As awkward as it sounds, it's easiest to think of a catalog as "something you don't have now, but would like to have on the Web page." For example, when a user closes an element on a Web page and wants it back later, she opens the catalog and selects the missing item. Visual Web Developer supports three kinds of catalogs through the The other two — the <asp:CatalogZone ID="CatalogZone1" Runat="server"> This control becomes active when the user selects the catalog verb from the Figure 2 shows a typical example of the Figure 2 : Add elements back onto the Web page using a PageCatalogPart. The Bottom Line WebParts technology is a new and decidedly welcome technology, with the ability to customize content turns your Web page from user-constraining to user-enriching. This article shows the power of WebParts technology and emphasizes the elements that don't require one iota of programming on your part. Even with the simple changes shown here, Web site visitors can create a completely custom viewing experience. With a little additional programming, you can create an application that not only makes desktop application users jealous, but actually exceeds the functionality that most desktop applications provide today. John Mueller is a freelance author and technical editor. He has writing in his blood, having produced 66 books and over 300 articles to date. The topics range from networking to artificial intelligence and from database management to heads down programming. His most recent book is FrontPage 2003 All-In One Desk Reference for Dummies (Wiley, ISBN 0764575317). His technical editing skills have helped over 35 authors refine the content of their manuscripts. |
http://www.devsource.com/article2/0,1759,1751857,00.asp