WebPartManager.CloseProviderWarning 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个警告,用户关闭在连接中充当其他控件的提供者的控件时,会显示该警告。
public:
virtual property System::String ^ CloseProviderWarning { System::String ^ get(); void set(System::String ^ value); };
public virtual string CloseProviderWarning { get; set; }
member this.CloseProviderWarning : string with get, set
Public Overridable Property CloseProviderWarning As String
属性值
一个包含警告消息的字符串。 默认值是一条由 .NET Framework 提供的、特定于区域性的消息。
示例
下面的代码示例演示如何使用 CloseProviderWarning 属性向用户显示自定义警告。
代码示例包含四个部分:
用户控件,可用于更改Web 部件页面上的显示模式。
一个源代码文件,其中包含两个自定义 WebPart 控件和一个自定义接口。
一个网页,其中包含两个可连接的自定义 WebPart 控件和一个
<asp:webpartmanager>
元素。说明示例在浏览器中的工作原理。
以下代码仅包含示例的网页部分。 还需要自定义用户控件和上述自定义控件的源代码。 从类概述的 WebPartManager “示例”部分获取这两项。
以下网页代码演示如何将自定义警告消息分配给 CloseProviderWarning 元素中声明性标记中的 <asp:webpartmanager>
属性。
<%@ Page Language="C#" %>
<%@ register TagPrefix="uc1"
TagName="DisplayModeMenuCS"
Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample"
Namespace="Samples.AspNet.CS.Controls"
Assembly="ConnectionSampleCS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<!-- Reference the WebPartManager control. -->
<asp:WebPartManager ID="WebPartManager1" runat="server"
CloseProviderWarning="You are closing a provider control." />
<div>
<uc1:DisplayModeMenuCS ID="displaymode1" runat="server" />
<!-- Reference consumer and provider controls in a zone. -->
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<aspSample:ZipCodeWebPart ID="zip1"
runat="server"
Title="Zip Code Control"/>
<aspSample:WeatherWebPart ID="weather1"
runat="server"
Title="Weather Control" />
</ZoneTemplate>
</asp:WebPartZone>
<hr />
<!-- Add a ConnectionsZone so users can connect controls. -->
<asp:ConnectionsZone ID="ConnectionsZone1" runat="server" />
</div>
</form>
</body>
</html>
<%@ Page Language="vb" %>
<%@ register TagPrefix="uc1"
TagName="DisplayModeMenuVB"
Src="DisplayModeMenuVB.ascx" %>
<%@ register tagprefix="aspSample"
Namespace="Samples.AspNet.VB.Controls"
Assembly="ConnectionSampleVB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<!-- Reference the WebPartManager control. -->
<asp:WebPartManager ID="WebPartManager1" runat="server"
CloseProviderWarning="You are closing a provider control." />
<div>
<uc1:DisplayModeMenuVB ID="displaymode1" runat="server" />
<!-- Reference consumer and provider controls in a zone. -->
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<aspSample:ZipCodeWebPart ID="zip1"
runat="server"
Title="Zip Code Control"/>
<aspSample:WeatherWebPart ID="weather1"
runat="server"
Title="Weather Control" />
</ZoneTemplate>
</asp:WebPartZone>
<hr />
<!-- Add a ConnectionsZone so users can connect controls. -->
<asp:ConnectionsZone ID="ConnectionsZone1" runat="server" />
</div>
</form>
</body>
</html>
在浏览器中加载网页后,单击 “显示模式”下拉列表控件,然后选择 连接 将页面切换为连接模式。 连接模式使用<asp:connectionszone>
元素在控件之间创建连接。 在连接模式下,单击 邮政编码 控件标题栏中的向下箭头以激活其谓词菜单,然后单击 连接。 (UI) 显示连接用户界面后,单击“ 创建与使用者”链接的连接 。 此时会显示一个包含下拉列表控件的单元格。 在下拉列表中选择 “天气控制”,然后单击 连接 以完成两个控件的连接。 单击“ 关闭”,然后使用 “显示模式 ”下拉列表将页面返回到普通浏览模式。 最后,单击邮政编码控件的谓 词 菜单, (,在本例中为提供程序控件,) 并选择 “关闭”。 将显示分配给该属性的 CloseProviderWarning 自定义消息。
注解
当用户关闭 WebPart 控件时,通常不会显示任何消息。 有关关闭控件的含义的详细信息,请参阅 CloseWebPart 该方法。
但是,当控件连接到另一个控件并且充当另一个控件的数据提供程序时,当用户尝试关闭控件时,将显示默认警告消息。 该消息告知用户,提供程序控件即将关闭,这意味着连接到此提供程序的控件,因为使用者将不再具有要使用的任何数据。 该 CloseProviderWarning 属性使开发人员能够自定义向用户显示的警告消息。
如果页面开发人员将空字符串值或 null 字符串值分配给此属性,则当用户关闭 WebPart 作为提供程序的控件时,不会显示任何警告消息框。