注意:此字段在 .NET Framework 2.0 版中是新增的。
表示最终用户可在其中编辑和修改服务器控件的显示模式。此字段为只读。
命名空间:System.Web.UI.WebControls.WebParts
程序集:System.Web(在 system.web.dll 中)
Public Shared ReadOnly EditDisplayMode As WebPartDisplayMode
Dim value As WebPartDisplayMode
value = WebPartManager.EditDisplayMode
public static readonly WebPartDisplayMode EditDisplayMode
public:
static initonly WebPartDisplayMode^ EditDisplayMode
public static final WebPartDisplayMode EditDisplayMode
public static final var EditDisplayMode : WebPartDisplayMode
EditDisplayMode 字段引用一个自定义 WebPartDisplayMode 对象,该对象由 WebPartManager 控件创建,并包含在该控件中。因为这是一个静态对象,所以可以通过 WebPartManager 类直接引用它,而无需该控件的实例。
默认情况下,包含 Web 部件的页在首次加载时处于 BrowseDisplayMode(浏览模式)。如果用户要编辑或修改服务器控件,则首先必须将页切换至 EditDisplayMode(编辑模式)。其次,用户必须通过单击该控件页眉中谓词菜单上的编辑谓词选择特定的服务器控件来进行编辑。控件处于编辑模式后,会显示编辑用户界面 (UI) 以编辑选定控件。
若要在某页启用编辑模式,该页必须包含至少一个 EditorZone 区域,该区域包括一个或多个提供的编辑控件(例如 LayoutEditorPart 控件)或自定义编辑控件。
下面的代码示例演示如何以编程方式使用 EditDisplayMode 字段。此代码使用受页支持的显示模式(在此示例中是浏览、设计和编辑模式)填充一个下拉列表。为支持编辑,该页中有一个 <asp:EditorZone> 元素。注意,在 Page_PreRender 方法中,代码会检查当前 DisplayMode 属性是否设置为 EditDisplayMode。如果是,则 Label1 将可见;否则 Label1 将隐藏。
<%@ Page Language="VB" %>
<script runat="server">
Protected Sub Page_Init(ByVal sender As Object, _
ByVal e As EventArgs)
Dim mode As WebPartDisplayMode
For Each mode In mgr.SupportedDisplayModes
Dim modeName As String = mode.Name
If mode.IsEnabled(mgr) Then
Dim item As ListItem = New ListItem(modeName, modeName)
DisplayModeDropdown.Items.Add(item)
End If
Next
End Sub
Protected Sub DisplayModeDropdown_SelectedIndexChanged(ByVal _
sender As Object, ByVal e As EventArgs)
Dim selectedMode As String = _
DisplayModeDropdown.SelectedValue
Dim mode As WebPartDisplayMode = _
mgr.SupportedDisplayModes(selectedMode)
If mode IsNot Nothing Then
mgr.DisplayMode = mode
End If
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, _
ByVal e As System.EventArgs)
If mgr.DisplayMode.Equals(WebPartManager.EditDisplayMode) Then
Label1.Visible = True
Else
Label1.Visible = False
End If
End Sub
</script>
<html >
<head runat="server">
</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:Label ID="Label1" runat="server"
Text="Currently in Edit Mode"
Font-Bold="true"
Font-Size="125%" />
<br />
<asp:DropDownList ID="DisplayModeDropdown" runat="server"
AutoPostBack="true"
Width="120"
OnSelectedIndexChanged=
"DisplayModeDropdown_SelectedIndexChanged">
</asp:DropDownList>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Init(object sender, EventArgs e)
{
foreach (WebPartDisplayMode mode in mgr.SupportedDisplayModes)
{
string modeName = mode.Name;
if (mode.IsEnabled(mgr))
{
ListItem item = new ListItem(modeName, modeName);
DisplayModeDropdown.Items.Add(item);
}
}
}
protected void DisplayModeDropdown_SelectedIndexChanged(object
sender, EventArgs e)
{
String selectedMode = DisplayModeDropdown.SelectedValue;
WebPartDisplayMode mode =
mgr.SupportedDisplayModes[selectedMode];
if (mode != null)
mgr.DisplayMode = mode;
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (mgr.DisplayMode == WebPartManager.EditDisplayMode)
Label1.Visible = true;
else
Label1.Visible = false;
}
</script>
<html >
<head runat="server">
</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:Label ID="Label1" runat="server"
Text="Currently in Edit Mode"
Font-Bold="true"
Font-Size="125%" />
<br />
<asp:DropDownList ID="DisplayModeDropdown" runat="server"
AutoPostBack="true"
Width="120"
OnSelectedIndexChanged=
"DisplayModeDropdown_SelectedIndexChanged">
</asp:DropDownList>
</div>
</form>
</body>
</html>
默认情况下,在浏览器中加载页后会处于浏览模式。注意,页上的标签是隐藏的。使用下拉列表控件将页切换至编辑模式。注意,由于 Page_PreRender 方法中的代码,该标签现在可见。单击控件之一的谓词菜单中的“编辑”谓词,启用对特定控件的编辑。
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
.NET Framework
受以下版本支持:2.0