1可以拖动
2可以隐藏和删除
3添加任意webpart
永久实现的因为存在数据库中.
包含三个部分:
个性化设置,webPart区域,webPart本身. webPart区域是容器.
webPart 控件 :
webPartManager用于管理页面上的所有的webPart控件,每个webPart控件都需要一个切只需要一个webPartManager控件.
在现在的网站设计中,更强调的是用户的个性化设置,让用户可以自由的设置符合自己喜好的页面成为网站开发人员的头号难题,不过现在看来这个难题微软帮我们解决了。在asp.net 2.0中新增加了一系列webpart控件,可以让用户很方便地对网页的各区域布局进行调整。在一些web应用程序中,如果用户想自定义页面布局,比如一个新闻发布系统,想让左,中,右三栏的位置进行调换的话,就可以使用webpart控件。
下面,我们来看下asp.net 2.0中webpart系列控件的一些基本用法。
首先,在vs.net 2005 中的工具箱中,可以找到如下图所示的webpart系列控件,有很多个,限于篇幅,本文介绍其中的一些重要的控件:
Response.Write(Page.IsValid) Dim queryStr As String = HttpUtility.UrlEncode(txtSearch.Text) Response.Redirect("http://www.google.com/search?q=" & queryStr) End Sub |
<uc1:Google title="Google Search" runat="server" ID="Google1" /> |
CloseVerb.ImageUrl="Images/CloseVerb.gif" EditVerb.ImageUrl="Images/EditVerb.gif" MinimizeVerb.ImageUrl="Images/MinimizeVerb.gif" RestoreVerb.ImageUrl="Images/RestoreVerb.gif" |
<asp:RadioButtonList ID="rblMode" runat="server" AutoPostBack="True"> <asp:ListItem>Browse Display Mode</asp:ListItem> <asp:ListItem>Design Display Mode</asp:ListItem> </asp:RadioButtonList> |
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 |
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 |
<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> |
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 |
<ZoneTemplate> <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server"> <WebPartsTemplate> <uc1:Google title="Google Search" ID="Google2" runat="server" /> </WebPartsTemplate> </asp:DeclarativeCatalogPart> |
<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:ListItem>Edit Display Mode</asp:ListItem> </asp:RadioButtonList> |
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 Case 3 : WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode End Select End Sub |
Imports Microsoft.VisualBasic Public Interface ISelectedDate ReadOnly Property SelectedDate( ) As Date End Interface |
Partial Class CalendarUC_ascx Inherits System.Web.UI.UserControl Implements ISelectedDate Public ReadOnly Property SelectedDate( ) As Date Implements ISelectedDate.SelectedDate Get Return Calendar1.SelectedDate.Date End Get End Property <ConnectionProvider("SelectedDate", "SelectedDate")> _ Public Function GetSelectedDate( ) As ISelectedDate Return Me End Function End Class |
Private _selectedDate As ISelectedDate <ConnectionConsumer("SelectedDate", "SelectedDate")> _ Sub setSearchText(ByVal SearchText As ISelectedDate) Me._selectedDate = SearchText End Sub Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender If _selectedDate IsNot Nothing Then txtSearch.Text = _selectedDate.SelectedDate.ToShortDateString End If End Sub |
<ZoneTemplate> <uc1:Google title="Google Search" runat="server" ID="Google1" /> <uc3:CalendarUC title="Calendar Web Part" runat="server" ID="CalendarUC1" /> </ZoneTemplate> |
<asp:WebPartManager ID="WebPartManager1" runat="server"> <StaticConnections> <asp:WebPartConnection ID="Connection" ProviderID="CalendarUC1" ProviderConnectionPointID="SelectedDate" ConsumerID="Google1" ConsumerConnectionPointID="SelectedDate" /> </StaticConnections> </asp:WebPartManager> |
Case 4 : WebPartManager1.DisplayMode = WebPartManager.ConnectDisplayMode |