Export (0) Print
Expand All

IWebActionable Interface

Note: This interface is new in the .NET Framework version 2.0.

Enables WebPart controls or other server controls to contain collections of verbs.

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in system.web.dll)

public interface IWebActionable
public interface IWebActionable
public interface IWebActionable

A verb in the Web Parts control set is an action that a user can carry out in the user interface (UI). Typically, a verb is represented in the UI by a clickable control such as a button, a link, or a menu item. The Web Parts control set provides standard verbs that are available by default to WebPart controls and other server controls (such as custom, ASP.NET, and user controls) that can act like WebPart controls when placed in WebPartZoneBase zones. Standard verbs include verbs such as close, minimize, restore, delete, edit, and export.

It is also possible to create custom verbs for use with WebPart and server controls. The IWebActionable interface, with its Verbs property, exists to give developers a way to integrate custom verbs into their controls. The WebPart class implements the IWebActionable interface and overrides its lone property. To add custom verbs to a control that inherits from the WebPart class, you must override the WebPart.Verbs property, add custom verbs to a collection, and return the collection. Notice that the collection referenced by the WebPart.Verbs property contains only custom verbs; standard verbs are not included in this collection. The default return value of the WebPart.Verbs property in a WebPart control is a null reference (Nothing in Visual Basic), because by default there are no custom verbs in the collection.

Adding custom verbs to server controls that are not WebPart controls requires one extra step. These server controls must also implement the IWebActionable interface, as well as overriding the Verbs property to add custom verbs to a collection.

After you have added custom verbs to the Verbs collection on a WebPart or server control, the Web Parts control set automatically handles the other steps necessary for creation and rendering of the custom verbs.

The following code example demonstrates a simple implementation of the IWebActionable interface.

The first part of the code example shows how the interface is implemented in a user control. The user control implements the Verbs property by creating two custom verbs and defining a method that executes when a user clicks either of the verbs. For simplicity, the same method is used. Note that the method updates the value of a property named VerbCounterClicks. Note also that the code for the Page_Load method accesses the Verbs property of the control, to display the total count of custom verbs in the collection. This count does not include the standard Web Parts verbs.

<%@ control language="C#" classname="AccountUserControl" %>
<%@ implements 
    interface="System.Web.UI.WebControls.WebParts.IWebActionable" %>
<%@ Import Namespace="System.ComponentModel" %>

<script runat="server">

  private WebPartVerbCollection m_Verbs;
  
  [Personalizable]
  public string UserName
  {
    get
    {
      if (String.IsNullOrEmpty(Textbox1.Text) || 
        Textbox1.Text.Length < 0)
        return String.Empty;
      else
        return Textbox1.Text;
    }
    
    set
    {
      Textbox1.Text = value;
    }
  }
    
  [Personalizable]
  public string Phone
  {
    get
    {
      if(String.IsNullOrEmpty(Textbox2.Text) || 
        Textbox2.Text.Length < 0)
        return String.Empty;
      else
        return Textbox2.Text;
    }
    
    set
    {
      Textbox2.Text = value;
    }
  }

  // The following code handles the verbs.
  [Personalizable]
  public int VerbCounterClicks
  {
    get
    {
      object objVerbCounter = ViewState["VerbCounterClicks"];
      int VerbCounterClicks = 0;
      if (objVerbCounter != null)
        VerbCounterClicks = (int)objVerbCounter;

      return VerbCounterClicks;
    }
    set
    {
      ViewState["VerbCounterClicks"] = value;
    }
  }

  private void IncrementVerbCounterClicks(object sender, 
    WebPartEventArgs e)
  {
    VerbCounterClicks += 1;
    Label4.Text = "Custom Verbs Click Count: " + 
      this.VerbCounterClicks.ToString();
  }

  void Page_Load(object sender, EventArgs e)
  {
    Label3.Text = "Custom Verb Count:  " +
      WebPartManager.GetCurrentWebPartManager(Page).
      WebParts[0].Verbs.Count.ToString();
  }


  // This property implements the IWebActionable interface.
  WebPartVerbCollection IWebActionable.Verbs
  {
    get
    {
      if (m_Verbs == null)
      {
        ArrayList verbsList = new ArrayList();
        WebPartVerb onlyVerb = new WebPartVerb
          ("customVerb1", new WebPartEventHandler(IncrementVerbCounterClicks));
        onlyVerb.Text = "My Verb";
        onlyVerb.Description = "VerbTooltip";
        onlyVerb.Visible = true;
        onlyVerb.Enabled = true;
        verbsList.Add(onlyVerb);
        WebPartVerb otherVerb = new WebPartVerb
          ("customVerb2", new WebPartEventHandler(IncrementVerbCounterClicks));
        otherVerb.Text = "My other Verb";
        otherVerb.Description = "Other VerbTooltip";
        otherVerb.Visible = true;
        otherVerb.Enabled = true;
        verbsList.Add(otherVerb);
        m_Verbs = new WebPartVerbCollection(verbsList);
        return m_Verbs;
      }
      return m_Verbs;
    }
  }
  
</script>
<div>
<asp:label id="Label1" runat="server">Name</asp:label>
<asp:textbox id="Textbox1" runat="server" />
</div>
<div>
<asp:label id="Label2" runat="server">Phone</asp:label>
<asp:textbox id="Textbox2" runat="server"></asp:textbox>
</div>
<div>
<asp:button id="Button2" runat="server" text="Save Form Values" />
</div>
<hr />
<br />
<asp:Label ID="Label3" runat="server" Text="" />
<br />
<asp:Label ID="Label4" runat="server" Text="" />

The second part of the code example is an .aspx page that hosts the user control. Because the control is referenced within a WebPartZone control, at run time ASP.NET wraps the user control in a GenericWebPart control, and treats it as a WebPart control. After you load the page in a browser, notice that the label at the bottom of the control displays how many custom verbs are contained in the collection referenced by the Verbs property. Also note that, if you click the verbs menu in the control, and click either of the verbs, another label appears, showing the total number of times the custom verbs have been clicked.

<%@ page language="c#" %>
<%@ register tagprefix="uc1" 
    tagname="AccountUserControl" 
    src="usercontrolverbcs.ascx"%>
<html>
  <head runat="server">
    <title>
      Personalizable User Control with IWebPart Properties
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <asp:webpartzone 
        id="zone1" 
        runat="server" 
        headertext="Main" 
        CloseVerb-Enabled="false">
        <zonetemplate>
          <uc1:AccountUserControl 
            runat="server" 
            id="accountwebpart" 
            title="Account Form" />
        </zonetemplate>
      </asp:webpartzone> 
    </form>
  </body>
</html>

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft