ImageButton.CommandArgument Własność
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Pobiera lub ustawia opcjonalny argument, który zawiera dodatkowe informacje o CommandName właściwości.
public:
property System::String ^ CommandArgument { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string CommandArgument { get; set; }
[System.ComponentModel.Bindable(true)]
[System.Web.UI.Themeable(false)]
public string CommandArgument { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.CommandArgument : string with get, set
[<System.ComponentModel.Bindable(true)>]
[<System.Web.UI.Themeable(false)>]
member this.CommandArgument : string with get, set
Public Property CommandArgument As String
Wartość nieruchomości
Opcjonalny argument, który uzupełnia CommandName właściwość.
Implementuje
- Atrybuty
Przykłady
W poniższym przykładzie pokazano, jak za pomocą CommandArgument właściwości skojarzyć argument polecenia z kontrolką ImageButton .
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 z rozszerzeniem .aspx. Aby uzyskać więcej informacji na temat modelu kodu formularzy internetowych, zobacz model kodu strony formularzy internetowych ASP.NET.
<%@ 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
Czasami wiele ImageButton kontrolek jest powiązanych i współużytkuje tę samą wartość dla CommandName właściwości, na przykład Sort. Użyj tej właściwości, aby uzupełnić CommandName właściwość dodatkowymi informacjami o poleceniu do wykonania, na przykład Ascending. Wartości właściwości i CommandArgument są zwykle używane w procedurze OnCommand obsługi zdarzeń w celu określenia akcji do wykonania po kliknięciu kontrolkiImageButton.CommandName
Nie można ustawić tej właściwości według motywów ani motywów arkusza stylów. Aby uzyskać więcej informacji, zobacz ThemeableAttributei ASP.NET Motywy i skóry.