WebPartManager.DisplayMode 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置包含 Web 部件控件的网页的活动显示模式。
public:
virtual property System::Web::UI::WebControls::WebParts::WebPartDisplayMode ^ DisplayMode { System::Web::UI::WebControls::WebParts::WebPartDisplayMode ^ get(); void set(System::Web::UI::WebControls::WebParts::WebPartDisplayMode ^ value); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.WebControls.WebParts.WebPartDisplayMode DisplayMode { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.DisplayMode : System.Web.UI.WebControls.WebParts.WebPartDisplayMode with get, set
Public Overridable Property DisplayMode As WebPartDisplayMode
属性值
确定页显示模式的 WebPartDisplayMode。
- 属性
例外
赋给该属性的 WebPartDisplayMode 对象为 null
。
示例
下面的代码示例演示了对 DisplayMode 属性的编程用法。 在浏览器中加载页面后,可以使用页面底部附近的按钮切换显示模式。 默认情况下,页面在加载时处于浏览模式。 如果切换到设计模式,则可以将服务器控件从一个区域拖动到另一个区域,或在一个区域中排列两个控件。 如果切换到编辑模式,可以在任一服务器控件的标头中单击谓词菜单,选择“ 编辑”,然后使用提供的编辑用户界面 (UI) 编辑控件。
备注
在Web 部件应用程序中的显示模式之间切换非常常见,你可能希望提供一致且可重用的方法,用于在包含Web 部件控件的所有页面上执行此操作。 有关更改显示模式且可在多个页面上重复使用的用户控件的示例,请参阅演练:更改Web 部件页面上的显示模式。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
mgr.DisplayMode = WebPartManager.BrowseDisplayMode;
}
protected void Button2_Click(object sender, EventArgs e)
{
mgr.DisplayMode = WebPartManager.DesignDisplayMode;
}
protected void Button3_Click(object sender, EventArgs e)
{
mgr.DisplayMode = WebPartManager.EditDisplayMode;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:WebPartManager ID="mgr" runat="server">
</asp:WebPartManager>
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<asp:Calendar ID="Calendar1" runat="server"
Title="My Calendar" />
</ZoneTemplate>
</asp:WebPartZone>
<asp:WebPartZone ID="WebPartZone2" runat="server">
<ZoneTemplate>
<asp:BulletedList
DisplayMode="HyperLink"
ID="BulletedList1"
runat="server"
Title="My Links">
<asp:ListItem Value="http://www.microsoft.com">Microsoft</asp:ListItem>
<asp:ListItem Value="http://www.msn.com">MSN</asp:ListItem>
<asp:ListItem Value="http://www.contoso.com">Contoso Corp.</asp:ListItem>
</asp:BulletedList>
</ZoneTemplate>
</asp:WebPartZone>
<asp:EditorZone ID="EditorZone1" runat="server">
<ZoneTemplate>
<asp:AppearanceEditorPart runat="server" ID="Appearance1">
</asp:AppearanceEditorPart>
<asp:LayoutEditorPart runat="server" ID="Layout1">
</asp:LayoutEditorPart>
</ZoneTemplate>
</asp:EditorZone>
<hr />
<asp:Button ID="Button1" runat="server" Text="Browse Mode" OnClick="Button1_Click" />
<br />
<asp:Button ID="Button2" runat="server" Text="Design Mode" OnClick="Button2_Click"/>
<br />
<asp:Button ID="Button3" runat="server" Text="Edit Mode" OnClick="Button3_Click"/>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs)
mgr.DisplayMode = WebPartManager.BrowseDisplayMode
End Sub
Protected Sub Button2_Click(ByVal sender As Object, _
ByVal e As EventArgs)
mgr.DisplayMode = WebPartManager.DesignDisplayMode
End Sub
Protected Sub Button3_Click(ByVal sender As Object, _
ByVal e As EventArgs)
mgr.DisplayMode = WebPartManager.EditDisplayMode
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:WebPartManager ID="mgr" runat="server">
</asp:WebPartManager>
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<asp:Calendar ID="Calendar1" runat="server"
Title="My Calendar" />
</ZoneTemplate>
</asp:WebPartZone>
<asp:WebPartZone ID="WebPartZone2" runat="server">
<ZoneTemplate>
<asp:BulletedList
DisplayMode="HyperLink"
ID="BulletedList1"
runat="server"
Title="My Links">
<asp:ListItem Value="http://www.microsoft.com">Microsoft</asp:ListItem>
<asp:ListItem Value="http://www.msn.com">MSN</asp:ListItem>
<asp:ListItem Value="http://www.contoso.com">Contoso Corp.</asp:ListItem>
</asp:BulletedList>
</ZoneTemplate>
</asp:WebPartZone>
<asp:EditorZone ID="EditorZone1" runat="server">
<ZoneTemplate>
<asp:AppearanceEditorPart runat="server" ID="Appearance1">
</asp:AppearanceEditorPart>
<asp:LayoutEditorPart runat="server" ID="Layout1">
</asp:LayoutEditorPart>
</ZoneTemplate>
</asp:EditorZone>
<hr />
<asp:Button ID="Button1" runat="server" Text="Browse Mode" OnClick="Button1_Click" />
<br />
<asp:Button ID="Button2" runat="server" Text="Design Mode" OnClick="Button2_Click"/>
<br />
<asp:Button ID="Button3" runat="server" Text="Edit Mode" OnClick="Button3_Click"/>
</div>
</form>
</body>
</html>
注解
包含Web 部件控件的页面始终处于多种可能的显示模式之一。 有关显示模式的详细信息,请参阅Web 部件页面显示模式。
该 WebPartManager 类为网页创建显示模式。 该控件使用基WebPartDisplayMode类WebPartManager创建多个标准显示模式对象,这些对象可在包含Web 部件控件的页面上使用。 类概述中 WebPartDisplayMode 介绍了这些标准显示模式。
该WebPartManager控件还管理使用Web 部件控件的页面的显示模式。 DisplayMode使用该属性,控件WebPartManager在页面上保留对当前显示模式的引用。 还可以使用该 DisplayMode 属性将页面切换到不同的显示模式。 有关在使用Web 部件控件的页面上更改显示模式的示例,请参阅演练:更改Web 部件页上的显示模式。
作为管理显示模式的一部分,控件WebPartManager还提供与显示模式相关的事件和OnDisplayModeChanging事件处理程序,如OnDisplayModeChanged方法和方法。 这些方法提供用于自定义页面行为的机制,甚至用于添加自定义显示模式。