ASP.NET 2.0中使用webpart系列控件(二)

翻译|其它|编辑:郝浩|2005-12-27 14:11:00.000|阅读 1301 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>


使webpart动起来

  上面设计的webpart还没能动起来,要让webpart动起来的话,必须要将webpar设置为design display 模式。先为webpart添加下面的radiobutton选择框

<asp:RadioButtonList ID="rblMode" runat="server" AutoPostBack="True">
 <asp:ListItem>Browse Display Mode</asp:ListItem>
 <asp:ListItem>Design Display Mode</asp:ListItem>
</asp:RadioButtonList>

  并且在code-behind的代码中,写入如下代码:

Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles rblMode.SelectedIndexChanged
 Select Case rblMode.SelectedIndex
  Case 0 : WebPartManager1.DisplayMode =WebPartManager.BrowseDisplayMode
  Case 1 : WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode
 End Select
End Sub 

  运行上面代码,选择design display mode,

  要注意的是,当移动各webpart的位置后,即使关掉浏览器,下次重新打开时,依然可以看到各个控件保持原来的位置。其实,asp.net 2.0是使用在aspnetdb.mdf中的一个叫aspnet_PersonalizationPerUser的表来保存数据的,表的结构如下所示:

Field Value
Id 928e121a-4042-4fb4-9520-21210b9b37c1
PathId 7c3b5dc0-04d0-48a2-bbb2-2b70286f22fe
UserId 9bff14df-024f-4bda-9a0a-b4a19ab9e387
PageSettings <Binary data>
LastUpdatedDate 10/06/2005 4:44:05 AM

   如果想恢复各控件的原来位置,只需要将该数据表中相应的行删除掉就可以了。但有个问题是,如果使用每一个webpart的关闭按钮,则很难再将其恢复(当然删除数据表中的行,但十分麻烦)。在asp.net 2.0中,提供了另一种webpart,叫做catlogzone控件,下面介绍其用法:

  1、往窗体中拖拉一个catlogzone控件,

  2、往该catlogzone控件区域中,再拖放三个webpart系列的控件,分别是DeclarativeCatalogPart, PageCatalogPart, and ImportCatalogPart,如下图所示。其中,DeclarativeCatalogPart控件的作用是,显示目前页面上有哪些可以用的webpart控件;PageCatalogPart的作用是,可以让用户通过勾选的方式,选定将哪些控件添加转移到其他webpart区域中去。ImportCatalogPart则可以通过外部磁盘文件的方式,加载其他做好了的webpart部件。

  3、在radiobutton区域中,修改以下代码,增添一个catalog display的显示模式:

<asp:RadioButtonList ID="rblMode" runat="server" AutoPostBack="True">
<asp:ListItem>Browse Display Mode</asp:ListItem>
<asp:ListItem>Design Display Mode</asp:ListItem>
<asp:ListItem>Catalog Display Mode</asp:ListItem>
</asp:RadioButtonList>

  然后,在code-behind的代码中,将代码修改为如下:

Protected Sub rblMode_SelectedIndexChanged( _
 ByVal sender As Object, _
 ByVal e As System.EventArgs) _
 Handles rblMode.SelectedIndexChanged
  Select Case rblMode.SelectedIndex
   Case 0 : WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode
   Case 1 : WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode
   Case 2 : WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode
  End Select
End Sub

  4、在DeclarativeCatalogPart任务菜单上,点击右上角的智能感知按钮,然后选"edit templates"的链接,进入模版编辑状态,


  再往其中的webpartstemplate区域中拖拉一个google.ascx控件,,这将允许用户在运行时,可以自由地往页面增加这样的google搜索控件。


  5、然后修改代码如下:

<ZoneTemplate>
<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
 <WebPartsTemplate>
  <uc1:Google title="Google Search" ID="Google2" runat="server" />
 </WebPartsTemplate>
</asp:DeclarativeCatalogPart>

  6、运行程序,可以看到,当选择catalog display mode时,会显示如下图所示的catalog zone,其中列出了当前可用的有哪些webpart控件,我们可以把这个google的控件加到其他的webpart区域,也可以尝试将已经存在的webpart控件关闭,然后在catalog zone区域中的控件列表中,把它们再加回到页面中去。


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP