Muokkaa

Jaa


WebPartManager.CloseProviderWarning Property

Definition

Gets or sets a warning that is displayed when a user closes a control that is acting as a provider to other controls in a connection.

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

Property Value

A string that contains the warning message. The default is a culture-specific message supplied by the .NET Framework.

Examples

The following code example demonstrates how to use the CloseProviderWarning property to display a custom warning to users.

The code example has four parts:

  • A user control that enables you to change display modes on a Web Parts page.

  • A source code file that contains two custom WebPart controls and a custom interface.

  • A Web page that contains two custom WebPart controls that can be connected and an <asp:webpartmanager> element.

  • An explanation of how the example works in a browser.

The following code contains only the Web page portion of the example. You will also need the custom user control and the source code for the custom controls mentioned above. Obtain these two items from the Example section of the WebPartManager class overview.

The following Web page code demonstrates how to assign a custom warning message to the CloseProviderWarning property in declarative markup in the <asp:webpartmanager> element.

<%@ 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>

After you have loaded the Web page in a browser, click the Display Mode drop-down list control and select Connect to switch the page to connect mode. Connect mode uses the <asp:connectionszone> element to enable you to create connections between controls. In connect mode, click the downward arrow in the title bar of the ZIP Code control to activate its verbs menu, and then click Connect. After the connection user interface (UI) appears, click the Create a connection to a Consumer link. A cell appears that has a drop-down list control. Select Weather Control in the drop-down list, and click Connect to complete the connection of the two controls. Click Close, and then use the Display Mode drop-down list to return the page to normal browse mode. Finally, click the verbs menu for the ZIP Code control (which is the provider control in this case) and select Close. The custom message you assigned to the CloseProviderWarning property is displayed.

Remarks

When a user closes a WebPart control, normally no message is displayed. For more information about what it means to close a control, see the CloseWebPart method.

However, when a control is connected to another control and is acting as a provider of data to the other control, a default warning message is displayed when a user attempts to close the control. The message tells users that a provider control is about to close, which means that controls connected to this provider as consumers will no longer have any data to consume. The CloseProviderWarning property enables developers to customize the warning message that is displayed to the user.

If a page developer assigns an empty or null string value to this property, no warning message box will be shown when a user closes a WebPart control that is a provider.

Applies to

See also