Adding Controls to Web Zones

You will now add controls to the Web zones that you placed in the previous lesson. You will then run //运行the page to see how all of these Web Part controls work together.

1. From the Toolbox drag a Calendar control into leftColWebPartZone, setting its ID property to "skedCalendar".

2.  Add a Web User Control called MyWebUserControl.ascx //<创建方法与其他文件创建的方法相同,就像创建Authors.aspx文件一样啦>to your project. 

3.  On the MyWebUserControl.ascx design surface, place some controls (such as shown here). You won't actually use these controls. It's just to demonstrate//示例说明 how you can make a Web Part out of a custom User Control.

4. From the Solution Explorer drag MyWebUserControl.ascx into midColWebPartZone. The user control is automatically loaded and displayed within the zone//在这个区域内.

You will now add a RadioButtonList control to handle the mode switching//模式转换.

5. From the ToolBox drag a RadioButtonList control onto the page, placing it below the WebPartManager control. In the RadioButtonList Tasks menu check Enable AutoPostBack, and then click Edit Items. In the ListItem Collection Editor dialog click Add. For Text enter "Browse" and for Selected select True. Click Add. For Text enter "Design", and then click OK.

6. Press ESC to close the RadioButtonList Tasks menu. Press F4 to access its properties, setting the ID property to "displayModeRadioButtonList", and RepeatDirection to Horizontal.

7. Double-click//双击 the RadioButtonList to add a SelectedIndexChanged event handler. To this handler add the following code, which sets the WebPartManager.DisplayMode property //属性based on the user's RadioButtonList selection//选择.

C# VB  
switch (RadioButtonList.SelectedIndex)
            {
            case 0:
            authorsWebPartManager.DisplayMode = WebPartManager.BrowseDisplayMode;
            break;
            default:
            authorsWebPartManager.DisplayMode = WebPartManager.DesignDisplayMode;
            break;
            }
            

Browse mode is the normal "locked" mode. Web Parts cannot be moved in this mode. In Design mode the user can move Web Parts from one zone to another. You will see this in action in a moment.

8. In the Solution Explorer select login.aspx and then press F5 to run the application. Log in as "johns" or "marys" with the password "Pa$$word!". From the navigation menu //导航菜单select Home | Web Parts.

It's important to log in first because Web Parts Design mode is only available to authenticated users. The user's customizations//用户化 are stored in the application's database. This is one aspect//方面 of a new ASP.NET 2.0 feature called Personalization//个性化.

9. Notice how the page looks in Browse mode. Hovering your mouse over a Web Part does not change the cursor to a move cursor//能够移动Web Part的鼠标形状,为"十"字型. All you can do is select Minimize or Close from the Web Part menu. However, do not select Close or you will lose the Web Part. You have not yet added a CatalogZone control for selecting and adding a Web Part from a list of available Web Parts. You will do this in the final Web Parts lesson.

10. In the RadioButtonList control select Design. Notice that Web Part Zone IDs appear and you can now click and drag a Web Part to another zone.

 

You can re-run your site and log in//登入 as the other user. You will notice that when you go to the WebParts.aspx page that the Web Parts are in their original place//原地. If you then log back in//回来登入 as the original user //原始用户you will see that the changes you made to Web Part locations are preserved//被保护的. Again, this is called personalization. The first user set up//设置 the Web Parts as they like them, and their settings were saved in the application database so their user experience is "personalized"//个性化 when they return to the page.

posted on 2007-04-13 10:55  改变热爱  阅读(234)  评论(0)    收藏  举报

导航