ImageButton.CommandArgument 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定提供 CommandName 屬性額外資訊的選擇性引數。
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
屬性值
搭配 CommandName 屬性的選擇性引數。
實作
- 屬性
範例
下列範例示範如何使用 CommandArgument 屬性,將命令引數與 ImageButton 控制項產生關聯。
注意
下列程式碼範例會使用單一檔案程式碼模型,如果直接複製到程式碼後置檔案,可能無法正常運作。 此程式碼範例必須複製到副檔名為 .aspx 的空白文字檔中。 如需Web Form程式碼模型的詳細資訊,請參閱ASP.NET Web Forms頁碼模型。
<%@ 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>
備註
有時候,多個 ImageButton 控制項相關,並共用屬性的 CommandName 相同值,例如 Sort
。 使用這個屬性來補充 CommandName 屬性,以及要執行之命令的其他資訊,例如 Ascending
。 和 屬性的值 CommandName 通常用於事件處理常式, OnCommand 以判斷按一下控制項時 ImageButton 要執行的 CommandArgument 動作。
這個屬性無法由佈景主題或樣式表主題設定。 如需詳細資訊,請參閱 ThemeableAttribute 和ASP.NET 主題和麵板。