ImageButton.Command Evento
Definição
Ocorre quando o ImageButton é clicado.Occurs when the ImageButton is clicked.
public:
event System::Web::UI::WebControls::CommandEventHandler ^ Command;
public:
virtual event System::Web::UI::WebControls::CommandEventHandler ^ Command;
public event System.Web.UI.WebControls.CommandEventHandler Command;
member this.Command : System.Web.UI.WebControls.CommandEventHandler
Public Custom Event Command As CommandEventHandler
Tipo de evento
Implementações
Exemplos
O exemplo a seguir demonstra como especificar e codificar um manipulador para o Command evento para determinar qual ImageButton controle é clicado.The following example demonstrates how to specify and code a handler for the Command event to determine which ImageButton control is clicked.
Observação
O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente para um arquivo code-behind.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. Este exemplo de código deve ser copiado em um arquivo de texto vazio que tenha uma extensão. aspx.This code sample must be copied into an empty text file that has an .aspx extension. Para obter mais informações sobre o modelo de código Web Forms, consulte modelo de código de página do ASP.NET Web Forms.For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.
<%@ Page Language="C#" AutoEventWireup="True" %>
<!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>
<title>ImageButton CommandName Sample</title>
<script language="C#" runat="server">
void ImageButton_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Sort" && e.CommandArgument == "Ascending")
Label1.Text = "You clicked the Sort Ascending Button";
else
Label1.Text = "You clicked the Sort Descending Button";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageButton CommandName Sample</h3>
Click an image.<br /><br />
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText="Sort Ascending"
ImageUrl="images/pict.jpg"
OnCommand="ImageButton_Command"
CommandName="Sort"
CommandArgument="Ascending"/>
<asp:ImageButton id="imagebutton2" runat="server"
AlternateText="Sort Descending"
ImageUrl="image/pict2.jpg"
OnCommand="ImageButton_Command"
CommandName="Sort"
CommandArgument="Descending"/>
<br /><br />
<asp:label id="Label1" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!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>
<title>ImageButton CommandName Sample</title>
<script language="VB" runat="server">
Sub ImageButton_Command(sender As Object, e As CommandEventArgs)
If (e.CommandName = "Sort") And (e.CommandArgument = "Ascending") Then
Label1.Text = "You clicked the Sort Ascending Button"
Else
Label1.Text = "You clicked the Sort Descending Button"
End If
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageButton CommandName Sample</h3>
Click an image.<br /><br />
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText="Sort Ascending"
ImageUrl="images/pict.jpg"
OnCommand="ImageButton_Command"
CommandName="Sort"
CommandArgument="Ascending"/>
<asp:ImageButton id="imagebutton2" runat="server"
AlternateText="Sort Descending"
ImageUrl="images/pict2.jpg"
OnCommand="ImageButton_Command"
CommandName="Sort"
CommandArgument="Descending"/>
<br /><br />
<asp:label id="Label1" runat="server"/>
</form>
</body>
</html>
Comentários
O Command evento é gerado quando um ImageButton controle é clicado.The Command event is raised when an ImageButton control is clicked.
Observação
O Command evento é gerado por meio da hierarquia de controle na forma de BubbleEvent .The Command event is raised through the control hierarchy in the form of the BubbleEvent.
Observação
Esse evento faz com que a página poste novamente no servidor.This event causes the page to post back to the server.
Para obter mais informações sobre como manipular eventos, consulte como: consumir eventos em um aplicativo Web Forms.For more information about handling events, see How to: Consume Events in a Web Forms Application.