Command.Click Evento
Definição
Ocorre quando o usuário ativa um controle Command.Occurs when a user activates a Command control. Esta API está obsoleta.This API is obsolete. Para saber mais sobre como desenvolver aplicativos móveis ASP.NET, veja Mobile Apps & Sites with ASP.NET (Aplicativos móveis e sites com ASP.NET).For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.
public:
event EventHandler ^ Click;
public event EventHandler Click;
member this.Click : EventHandler
Public Custom Event Click As EventHandler
Tipo de evento
Exemplos
O exemplo de código a seguir demonstra como anexar eventos de comando.The following code example demonstrates how to attach command events. Clicar em um dos Command botões gera o OnItemCommand evento.Clicking either of the Command buttons raises the OnItemCommand event. A função definida pelo usuário usa o CommandEventArgs argumento para ver qual Command botão foi clicado.The user-defined function uses the CommandEventArgs argument to see which Command button was 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 example 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 example 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#"
Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Mobile" %>
<script runat="server">
//<Snippet3>
public void Page_Load(Object sender, EventArgs e)
{
MobileCapabilities caps
= (MobileCapabilities)Request.Browser;
if (caps.MaximumSoftkeyLabelLength == 5)
{
Command1.SoftkeyLabel = "Click";
}
else if (caps.MaximumSoftkeyLabelLength > 5)
{
Command1.SoftkeyLabel = "Submit";
}
}
//</Snippet3>
void Command_Click(object sender, CommandEventArgs e)
{
string txt = "You clicked Button{0}. ({1} points)";
if (e.CommandName.ToString() == "Command1")
{
Label1.Text = String.Format(txt, 1,
e.CommandArgument);
}
else if (e.CommandName.ToString() == "Command2")
{
Label1.Text = String.Format(txt, 2,
e.CommandArgument);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:form id="form1" runat="server">
<mobile:Label id="Label1" runat="server">
Click a button
</mobile:Label>
<mobile:Label id="Label2" runat="server" />
<mobile:Command id="Command1" Format="Button"
OnItemCommand="Command_Click"
CommandName="Command1" runat="server"
Text="Button1" CommandArgument="70" />
<mobile:Command id="Command2" Format="Link"
OnItemCommand="Command_Click"
CommandName="Command2" runat="server"
Text="Button2" CommandArgument="50" />
</mobile:form>
</body>
</html>
<%@ Page Language="VB"
Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Mobile" %>
<script runat="server">
'<Snippet3>
Public Sub Page_Load(ByVal sender As Object, _
ByVal e As EventArgs)
Dim caps As System.Web.Mobile.MobileCapabilities _
= CType(Request.Browser, MobileCapabilities)
If caps.MaximumSoftkeyLabelLength = 5 Then
Command1.SoftkeyLabel = "Click"
ElseIf caps.MaximumSoftkeyLabelLength > 5 Then
Command1.SoftkeyLabel = "Submit"
End If
End Sub
'</Snippet3>
Private Sub Command_Click(ByVal sender As Object, _
ByVal e As CommandEventArgs)
Dim txt As String = "You clicked Button{0}. ({1} points)"
If e.CommandName.ToString() = "Command1" Then
Label1.Text = String.Format(txt, 1, e.CommandArgument)
ElseIf e.CommandName.ToString() = "Command2" Then
Label1.Text = String.Format(txt, 2, e.CommandArgument)
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:form id="form1" runat="server">
<mobile:Label id="Label1" runat="server">
Click a button
</mobile:Label>
<mobile:Label id="Label2" runat="server" />
<mobile:Command id="Command1" Format="Button"
OnItemCommand="Command_Click"
CommandName="Command1" runat="server"
Text="Button1" CommandArgument="70" />
<mobile:Command id="Command2" Format="Link"
OnItemCommand="Command_Click"
CommandName="Command2" runat="server"
Text="Button2" CommandArgument="50" />
</mobile:form>
</body>
</html>
Comentários
Quando um Command controle é ativado, ele gera o OnClick evento.When a Command control is activated, it raises the OnClick event. Para obter mais informações, consulte as seções "renderização específica do dispositivo" e "comportamento específico do dispositivo" em System.Web.UI.MobileControls.Command .For more information, see the "Device-Specific Rendering" and "Device-Specific Behavior" sections in System.Web.UI.MobileControls.Command.