One Of the new features in Visual Studio. NET is visual web developer, 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, Downloading the preview of Visual Web Developer Express. Advertisement Webparts 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 varous 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. 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 des 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 Way that makes it very difficult to decipher any participant 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 shoshould look, set properties to tell It how you want the page to act, and let the IDE generate most of 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 isWebpartmanager To control the customization,Webpartpagemenu To allow user changes, and one or more zones that define the customization. AddingWebpartmanager Before you do anything else, addWebpartmanager Control to the web page.Webpartmanager Control is the component that coordinates the efforts of all of the other controls that you add to the web page. 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 Toolbox or add it to the page in Source view, as shown here. <Asp: webpartmanager id = "webpartmanager1" runat = "server"> </ASP: webpartmanager> 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 addWebpartpagemenu Control to the page. This menu provides a list of selections or verbs which the user may use to make changes to the page.Webpartpagemenu Attaches each verb to a participantWebpart Control. For example, to give the user the opportunity to remove items from a page, you shoshould also provideWebpartcatalog Control to add the items back in. You'll discover more about these Modifiers as the example progresses. Here's a typical webpartpagemenu Control. <Asp: webpartpagemenu id = "webpartpagemenu1" Runat = "server" TEXT = "change the layout" Mode = "menu" Hoverstyle-borderwidth = "1" Menustyle-borderwidth = "1" Browsemodeverb-TEXT = "Browse" Designmodeverb-TEXT = "design" Editmodeverb-TEXT = "edit" Catalogmodeverb-TEXT = "catalog"> </ASP: webpartpagemenu>
Notice that this control has four verbs configured:
-
- The
Browsemodeverb Verb lets the user return to browse mode after making changes to the web page.
- The
Designmodeverb Verb lets the user move items Around on the screen. The user can't actually edit anything, but he can Move items to make them easier to use.
-
- The
Editmodeverb Verb displays a special set Editing tools. The user can choose one of these tools to move items From one area to another, change the appearance of the items, give Items a new title, and so on. This is an extremely powerful feature, But not so powerful so that you have to worry about anyone damaging Web site. webpart changes only affect the current user.
-
- The
Catalogmodeverb Verb displays a list of items that The user can add to the web page. This is a mandatory addition when you Allow the user to remove items from the web page because this is Only way the user can add the items back.
Once you haveWebpartmanager AndWebpartpagemenu Controls in place, you can design the movable content for the web page by adding varous zones to it. Two or moreWebpartzone Controls are essential. You use these controls to define the content That the user can modify as well as define the content that must appear On the page. The other zone controls work withWebpartzone Control to provide specific editing features. Creating content with the webpartzone A webpart web page contains two kinds of content:
- Content that the user can't modify. For example, you wouldn't
Want user to remove the company logo from a web page or modify Important content, such as warnings.
- Content that the user can change. If your web page contains des
Local weather and you feel that this information is ancillary, you can Permit the user to remove it (or at least move it out of the way). Second kind of content appears within a webpartzone control.
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 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 Content you coshould create. <Asp: webpartzone id = "wpztest" Runat = "server" Headertext = "content selections" Editverb-TEXT = "edit"> <Zonetemplate> <Asp: Label runat = "server" TEXT = "Hello the first time" Id = "lblgreeting1"/> <Asp: hyperlink id = "hlnowhere" Runat = "server" Navigateurl = "default. aspx"> Goes nowhere </ASP: hyperlink> </Zonetemplate> </ASP: webpartzone> <Asp: webpartzone id = "wpztest2" Runat = "server" Headertext = "alternate content selections" Editverb-TEXT = "edit"> <Zonetemplate> <Asp: Label runat = "server" TEXT = "Hello the second time" Id = "lblgreeting2"/> </Zonetemplate> </ASP: webpartzone> < TheWebpartzone Control acts as a container for the moveable content. You provide a verb for changing the content as part ofWebpartzone Control. When the user selects the control on screen and chooses Correct verb (edit, in this case), the control lets the user move Content around und, delete it, or change it in other ways. The content controls (labels and hyperlinks, here) appear within <Zonetemplate> tag. You must include this tag as a container 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 provideCatalogzone Control that lets the user add the content back onto the page. Otherwise, the content disappears for good, from the user's Perspective. (Remember, the changes only affect this user, Not your actual Web server or its data, so the content still exists .) Modifying the content withEditorzone Depending on what you want the user to do with the page, you can provide design and edit verbs onWebpartpagemenu Control. The design verb only lets the user move things around, while The Edit verb allows a lot more, such as removing content from view. When you include the edit verb, you also need to addEditorzone Control. The web page automatically displays the content of this Control when the user selects the edit verb. Here's an example ofEditorzone Control with two kinds of editors. <Asp: editorzone id = "editorzone1" runat = "server"> <Zonetemplate> <Asp: appearanceeditorpart runat = "server" Id = "appearanceeditorpart1"/> <Asp: layouteditorpart runat = "server" id = "layouteditorpart1"/> </Zonetemplate> </ASP: editorzone> As with most zone controls, you must placeEditorzone Control content within a <zonetemplate> tag. In this case, the application usesAppearanceeditorpart (Which changes the appearance of the control) andLayouteditorpart Control (which lets the user move the data elements around). As you can See from the code, you don't have to perform a lot of work to make These controls functional. Figure 1 shows both controls in action. 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 participant control displays both the appearanceeditorpart and layouteditorpart controls. notice that the appearanceeditorpart control lets the user change the title for the display element, as well as its width and height. the user can also choose to display the element with a title and border, or without either item. the user can even hide unwanted items from view. the layouteditorpart control makes it possible to move web page elements around and change their state from normal (viewable) to minimized (just the title showing ). the Zone Index field changes the control's position within a Participant zone. You can add other controls to the list.Behavioreditorpart Control lets the user change how the control interacts with the web page.Propertygrideditorpart Control lets the user change individual properties for the controls. Both controls require special programming to make them work. However, They're actually the exception to the rule. So far, all of Customization in this article works without any additional coding on Your part; you Simply design the page and set the required properties. Adding new items with the catalogzone In this context, a catalog isn't a list of acquirable items. Awkward as it sounds, it's easiest to think of a catalog as "something You don't have now, but wocould like to have on the web page." 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 throughCatalogzone Control.Pagecatalogpart Control is the easiest to use and the one that you'll add most often. It lets a user add closed items back onto the page. The other two-Declarativecatalogpart AndImportcatalogpart Controls-provide access to external elements And require special handling. Again, the coding you must perform to use Special features will probably be the exception, rather than the rule. Here's a sample ofPagecatalogpart Control. <Asp: catalogzone id = "catalogzone1" runat = "server"> <Zonetemplate> <Asp: pagecatalogpart id = "pagecatalogpart1" runat = "server"/> </Zonetemplate> </ASP: catalogzone> This control becomes active when the user selects the catalog verb fromWebpartpagemenu Control. Figure 2 shows a typical example ofPagecatalogpart Control in action. notice that it contains the closed element on this Web page. to display the element, the user checks the element Option (Untitled [1]), chooses a location from the add to field, and clicks Add. 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 viem 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 isFrontline page 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. |