ImageButton.Command Zdarzenie
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Występuje po kliknięciu ImageButton .
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
Typ zdarzenia
Implementuje
Przykłady
W poniższym przykładzie pokazano, jak określić i kodować procedurę obsługi dla Command zdarzenia w celu określenia, która ImageButton kontrolka jest klikana.
Uwaga
Poniższy przykładowy kod używa modelu kodu pojedynczego pliku i może nie działać poprawnie, jeśli został skopiowany bezpośrednio do pliku za pomocą kodu. Ten przykładowy kod musi zostać skopiowany do pustego pliku tekstowego, który ma rozszerzenie aspx. Aby uzyskać więcej informacji na temat modelu kodu Web Forms, zobacz ASP.NET Web Forms Page Code Model (Model kodu strony).
<%@ 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>
Uwagi
Zdarzenie Command jest wywoływane po kliknięciu kontrolki ImageButton .
Uwaga
Zdarzenie Command jest wywoływane przez hierarchię sterowania w postaci BubbleEvent
.
Uwaga
To zdarzenie powoduje, że strona zostanie ponownie wyświetlona na serwerze.
Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz How to: Consume Events in a Web Forms Application (Instrukcje: używanie zdarzeń w aplikacji Web Forms).
Dotyczy
Zobacz też
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla