IWebActionable Interface
Definição
public interface class IWebActionable
public interface IWebActionable
type IWebActionable = interface
Public Interface IWebActionable
- Derivado
Exemplos
O exemplo de código a seguir demonstra uma implementação simples da IWebActionable interface.The following code example demonstrates a simple implementation of the IWebActionable interface. A primeira parte do exemplo de código mostra como a interface é implementada em um controle de usuário.The first part of the code example shows how the interface is implemented in a user control. O controle de usuário implementa a Verbs Propriedade criando dois verbos personalizados e definindo um método que é chamado quando um usuário clica em um dos verbos.The user control implements the Verbs property by creating two custom verbs and defining a method that is called when a user clicks either of the verbs. Para simplificar, o mesmo método é usado para ambos os verbos.For simplicity, the same method is used for both verbs. O método atualiza o valor de uma propriedade chamada VerbCounterClicks .The method updates the value of a property named VerbCounterClicks. O código para o Page_Load método acessa a Verbs Propriedade do controle para exibir a contagem total de verbos personalizados na coleção.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. Essa contagem não inclui os verbos de Web Parts padrão.This count does not include the standard Web Parts verbs.
Importante
Este exemplo tem uma caixa de texto que aceita a entrada do usuário, que é uma possível ameaça à segurança.This example has a text box that accepts user input, which is a potential security threat. Por padrão, as páginas da Web do ASP.NET validam que a entrada do usuário não inclui elementos de script ou HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para obter mais informações, consulte Visão geral de explorações de script.For more information, see Script Exploits Overview.
<%@ 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();
}
// <snippet3>
// 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;
}
}
// </snippet3>
</script>
<div>
<asp:label id="Label1" runat="server" AssociatedControlID="Textbox1">
Name</asp:label>
<asp:textbox id="Textbox1" runat="server" />
</div>
<div>
<asp:label id="Label2" runat="server" AssociatedControlID="Textbox2">
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="" />
<%@ control language="vb" classname="AccountUserControlVB" %>
<%@ implements
interface="System.Web.UI.WebControls.WebParts.IWebActionable" %>
<%@ Import Namespace="System.ComponentModel" %>
<script runat="server">
Private m_Verbs As WebPartVerbCollection
<Personalizable()> _
Public Property UserName() As String
Get
If String.IsNullOrEmpty(Textbox1.Text) OrElse _
Textbox1.Text.Length < 0 Then
Return String.Empty
Else
Return Textbox1.Text
End If
End Get
Set(ByVal value As String)
Textbox1.Text = value
End Set
End Property
<Personalizable()> _
Public Property Phone() As String
Get
If String.IsNullOrEmpty(Textbox2.Text) OrElse _
Textbox2.Text.Length < 0 Then
Return String.Empty
Else
Return Textbox2.Text
End If
End Get
Set(ByVal value As String)
Textbox2.Text = value
End Set
End Property
' The following code handles the verbs.
<Personalizable()> _
Public Property VerbCounterClicks() As Integer
Get
Dim objVerbCounter As Object = _
ViewState("VerbCounterClicks")
VerbCounterClicks = 0
If Not (objVerbCounter Is Nothing) Then
VerbCounterClicks = CType(objVerbCounter, Int32)
End If
Return VerbCounterClicks
End Get
Set(ByVal value As Integer)
ViewState("VerbCounterClicks") = value
End Set
End Property
Private Sub IncrementVerbCounterClicks _
(ByVal sender As Object, ByVal e As WebPartEventArgs)
VerbCounterClicks += 1
Label4.Text = "Custom Verbs Click Count: " + _
Me.VerbCounterClicks.ToString()
End Sub
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Label3.Text = "Custom Verb Count: " + _
WebPartManager.GetCurrentWebPartManager(Page). _
WebParts(0).Verbs.Count.ToString()
End Sub
' <snippet3>
' This property implements the IWebActionable interface.
ReadOnly Property Verbs() As WebPartVerbCollection _
Implements IWebActionable.Verbs
Get
If (m_Verbs Is Nothing) Then
Dim verbsList As New ArrayList()
Dim onlyVerb As New WebPartVerb _
("customVerb1", New WebPartEventHandler(AddressOf IncrementVerbCounterClicks))
onlyVerb.Text = "My Verb"
onlyVerb.Description = "VerbTooltip"
onlyVerb.Visible = True
onlyVerb.Enabled = True
verbsList.Add(onlyVerb)
Dim otherVerb As New WebPartVerb _
("customVerb2", New WebPartEventHandler(AddressOf IncrementVerbCounterClicks))
otherVerb.Text = "My other Verb"
otherVerb.Description = "Other VerbTooltip"
otherVerb.Visible = True
otherVerb.Enabled = True
verbsList.Add(otherVerb)
m_Verbs = New WebPartVerbCollection(verbsList)
End If
Return m_Verbs
End Get
End Property
' </snippet3>
</script>
<div>
<asp:label id="Label1" runat="server" AssociatedControlID="Textbox1">
Name</asp:label>
<asp:textbox id="Textbox1" runat="server" />
</div>
<div>
<asp:label id="Label2" runat="server" AssociatedControlID="Textbox2">
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="" />
A segunda parte do exemplo de código é uma página. aspx que hospeda o controle de usuário.The second part of the code example is an .aspx page that hosts the user control. Como o controle é referenciado em um WebPartZone controle, em tempo de execução ASP.net encapsula o controle de usuário em um GenericWebPart controle e o trata como um WebPart controle.Because the control is referenced in a WebPartZone control, at run time ASP.NET wraps the user control in a GenericWebPart control and treats it as a WebPart control. Depois de carregar a página em um navegador, observe que o rótulo na parte inferior do controle exibe quantos verbos personalizados estão na coleção referenciada pela Verbs propriedade.After you load the page in a browser, notice that the label at the bottom of the control displays how many custom verbs are in the collection referenced by the Verbs property. Observe também que, se você clicar no menu de verbos no controle e clicar em qualquer um dos verbos, outro rótulo aparecerá mostrando o número total de vezes que os verbos personalizados foram clicados.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"%>
<!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 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>
<%@ page language="vb" %>
<%@ register tagprefix="uc1"
tagname="AccountUserControlVB"
src="usercontrolverbvb.ascx"%>
<!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 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:AccountUserControlVB
runat="server"
id="accountwebpart"
title="Account Form" />
</zonetemplate>
</asp:webpartzone>
</form>
</body>
</html>
Comentários
Um verbo nos WebPart controles é uma ação que um usuário pode executar na interface do usuário.A verb in WebPart controls is an action that a user can carry out in the user interface (UI). Normalmente, um verbo é representado na interface do usuário por um controle clicável, como um botão, um link ou um item de menu.Typically, a verb is represented in the UI by a clickable control such as a button, a link, or a menu item. O conjunto de controle de Web Parts fornece verbos padrão que estão disponíveis por padrão para WebPart controles e outros controles de servidor (como controles personalizados, ASP.net e de usuário) que podem agir como WebPart controles quando colocados em WebPartZoneBase zonas.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. Os verbos padrão incluem fechar, minimizar, restaurar, excluir, editar e exportar.Standard verbs include close, minimize, restore, delete, edit, and export.
Você também pode criar verbos personalizados para uso com WebPart e controles de servidor.You can also create custom verbs for use with WebPart and server controls. A IWebActionable interface, com sua Verbs propriedade, oferece uma maneira de integrar verbos personalizados em seus controles.The IWebActionable interface, with its Verbs property, gives you a way to integrate custom verbs into your controls. A WebPart classe implementa a IWebActionable interface e implementa sua única propriedade.The WebPart class implements the IWebActionable interface and implements its single property. Para adicionar verbos personalizados a um controle herdado da WebPart classe, você deve substituir a WebPart.Verbs propriedade, adicionar verbos personalizados a uma coleção e retornar a coleção.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. A coleção referenciada pela WebPart.Verbs propriedade contém somente verbos personalizados; os verbos padrão não estão incluídos nesta coleção.The collection referenced by the WebPart.Verbs property contains only custom verbs; standard verbs are not included in this collection. O valor de retorno padrão da WebPart.Verbs propriedade em um WebPart controle é null , porque, por padrão, não há verbos personalizados na coleção.The default return value of the WebPart.Verbs property in a WebPart control is null, because by default there are no custom verbs in the collection.
Adicionar verbos personalizados a controles de servidor que não são WebPart controles requer uma etapa extra.Adding custom verbs to server controls that are not WebPart controls requires one extra step. Nesses casos, os controles também devem implementar a IWebActionable interface e implementar a Verbs propriedade.In those cases, the controls must also implement the IWebActionable interface and implement the Verbs property.
Depois de adicionar verbos personalizados à Verbs coleção, o conjunto de controle de Web Parts manipula automaticamente as outras etapas necessárias para criar e renderizar os verbos personalizados.After you have added custom verbs to the Verbs collection, the Web Parts control set automatically handles the other steps necessary to create and render the custom verbs.
Propriedades
| Verbs |
Obtém uma referência a uma coleção de objetos WebPartVerb personalizados.Gets a reference to a collection of custom WebPartVerb objects. |