3.3. Let Users Move Web PartsNote: Let your users rearrange the positions of the Web Parts on your portal to their liking. So far we have been discussing how to create Web Parts and how to configure them to look good and nice. But we have not really touched on the most important feature of Web Partsthat is, how to let users move the Web Parts from one zone to another. 3.3.1. How do I do that?In this lab, you will learn how to use the ASP.NET 2.0 Web Parts Framework to enable users to move Web Parts directly in the web browser. First you'll add a pair of radio buttons to the page so you can turn the feature on and off, and then you'll observe the behavior of the Web Parts as you move them from one zone to another.
3.3.2. What just happened?What you have just seen is how to configure a Web Part so it can be moved from one Web Part zone to another, and you've observed how the look and feel and behavior of the Web Part itself change when you do that. All of this is handled by the WebPartManager control. When you click on the Browse Display Mode button, the display mode of the WebPartManager control is set to WebPartManager.DesignDisplayMode: Case 1 : WebPartManager1.DisplayMode = _ WebPartManager.DesignDisplayMode When you are done moving the Web Parts and want to finalize the positioning of the Web Parts on the page, you can simply set it back to browse mode: Case 0 : WebPartManager1.DisplayMode = _ WebPartManager.BrowseDisplayMode Now, if you close IE and press F5 in Visual Studio again, you will notice that the Web Parts remain in their most recent position. The Web Parts Framework is able to "remember" where you previously positioned them. So how is this done? Actually, the positional information of each Web Part is stored in a table called the aspnet_PersonalizationPerUser table, found in the ASPNETDB.MDF database (SQL Express 2005) located in the App_Data folder of your project. Table 3-1 shows a record in the aspnet_ PersonalizationPerUser table. Note: When I run the application on my system, the Id can be traced to the username "WINXP2\Wei-Meng Lee" in the aspnet_Users table, also located within the ASNETDB.MDF database.
If you wish to restore the Web Parts to their original position, simply delete the row (corresponding to a particular user) in the aspnet_PersonalizationPerUser table. 3.3.3. What about......restoring a Web Part after it has been closed? In the process of trying out the labs, you may have clicked on the Close button on a Web Part. If you did this, you might have had difficulty getting the page back. But fear not, the Web Parts are not gone forever; you just need to know how to get them back. There are two ways of restoring a closed Web Part:
You can always disable the Close link of a Web Part by setting the Visible attribute within the CloseVerb property to false. 3.3.4. Where can I learn more?To learn how to write your own custom personalization provider, check out the following articles:
|