共用方式為


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 屬性向用戶顯示自定義警告。

程式代碼範例有四個部分:

  • 使用者控制元件,可讓您變更網頁元件頁面上的顯示模式。

  • 原始碼檔案,其中包含兩個自定義 WebPart 控件和自定義介面。

  • 網頁,包含兩個可連接和元素的<asp:webpartmanager>自定義WebPart控件。

  • 說明範例在瀏覽器中的運作方式。

下列程式代碼只包含範例的網頁部分。 您也需要上述自定義控制元件的自訂使用者控制項和原始程式碼。 從類別概觀的 WebPartManager Example區段取得這兩個專案。

下列網頁程式代碼示範如何將自定義警告訊息指派給 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 提供者的控制件時,將不會顯示任何警告消息框。

適用於

另請參閱