WebPartManager.CloseProviderWarning 属性

定义

获取或设置一个警告,用户关闭在连接中充当其他控件的提供者的控件时,会显示该警告。

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 “示例”部分获取这两个项。

以下网页代码演示如何在 元素的声明性标记<asp:webpartmanager>中将CloseProviderWarning自定义警告消息分配给 属性。

<%@ 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 使开发人员能够自定义向用户显示的警告消息。

如果页面开发人员将空字符串值分配给此属性,则当用户关闭 WebPart 作为提供程序的控件时,将不会显示警告消息框。

适用于

另请参阅