Share via


Click Event

Occurs when a user activates a Command control.

public event EventHandler Click

Remarks

When a Command control is activated, it raises the OnClick event. For more information, see the Device-Specific Rendering section and the Device-Specific Behavior ** section in the Command control documentation.

Example

The following example demonstrates how to trap the OnClick event to change the list from a linked, numbered list to a bulleted list.

[Visual Basic]

<SCRIPT language="vb" runat="server">

Class Navigation
   Private _SiteName As String
   Private _URL As String
   
   
   Public Sub New(SiteName As String, URL As String)
      _SiteName = SiteName
      _URL = URL
   End Sub 'New
   
   
   Public ReadOnly Property SiteName() As String
      Get
         Return _SiteName
      End Get
   End Property
   
   Public ReadOnly Property URL() As String
      Get
         Return _URL
      End Get
   End Property
End Class


Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
   If Not IsPostBack Then
      List1.ForeColor = System.Drawing.Color.Red
      List1.Wrapping = System.Web.UI.MobileControls.Wrapping.NoWrap
      List1.DataValueField = "URL"
      List1.DataTextField = "SiteName"
   
      Dim arr As New ArrayList()
      arr.Add(New Navigation("ASP.NET Site", "https://msdn.microsoft.com" + "/vstudio/nextgen/technology/mitdefault.asp"))
      arr.Add(New Navigation("MSN Site", "https://www.msn.com"))
      arr.Add(New Navigation("Home Site", "https://www.microsoft.com"))
      List1.Decoration = System.Web.UI.MobileControls.ListDecoration.Numbered
      List1.DataSource = arr
      List1.ItemsAsLinks = True
      List1.DataBind()
  End If
End Sub


Sub cmd1_OnClick(sender As Object, e As EventArgs)
   List1.Decoration = System.Web.UI.MobileControls.ListDecoration.Bulleted
   List1.ItemsAsLinks = False
End Sub


Sub cmd2_OnClick(sender As Object, e As EventArgs)
   List1.Decoration = System.Web.UI.MobileControls.ListDecoration.Numbered
   List1.ItemsAsLinks = True
End Sub


</SCRIPT>
<mobile:Form runat="server" id="Form1" >
   <mobile:List runat="server" id="List1" />
   <mobile:command runat=server OnClick="cmd1_OnClick" 
      Text="Change Properties" ID="Command1" 
      NAME="Command1"/><br/><br/>&nbsp;
   <mobile:command runat=server OnClick="cmd2_OnClick" 
      Text="Reset Properties" ID="Command2" NAME="Command2"/>
</mobile:Form>
<script language="c#" runat="server">

class Navigation
{
   private String _SiteName;
   private String _URL;

   public Navigation(String SiteName, String URL) 
   { 
      _SiteName = SiteName; 
      _URL = URL;
   }

   public String SiteName { get { return _SiteName; } }
   public String URL { get { return _URL; } }
}

public void Page_Load(Object sender, EventArgs e)
{
   if (!IsPostBack)
   { 
      List1.ForeColor = System.Drawing.Color.Red;
      List1.Wrapping=System.Web.UI.MobileControls.Wrapping.NoWrap; 
      List1.DataValueField="URL";
      List1.DataTextField="SiteName";
      ArrayList arr = new ArrayList();
      arr.Add (new Navigation ("ASP.NET Site", "https://msdn.microsoft.com"
         + "/vstudio/nextgen/technology/mitdefault.asp"));
      arr.Add (new Navigation ("MSN Site", "https://www.msn.com"));
      arr.Add (new Navigation ("Home Site", "https://www.microsoft.com"));
      List1.Decoration=System.Web.UI.MobileControls.ListDecoration.Numbered;
      List1.DataSource = arr;
      List1.ItemsAsLinks = true;
      List1.DataBind ();
   }

}

void cmd1_OnClick(Object sender, EventArgs e)
{
   List1.Decoration=System.Web.UI.MobileControls.ListDecoration.Bulleted;
   List1.ItemsAsLinks = false;
}

void cmd2_OnClick(Object sender, EventArgs e)
{
   List1.Decoration=System.Web.UI.MobileControls.ListDecoration.Numbered;
   List1.ItemsAsLinks = true;
}

</script>

<mobile:Form runat="server" id="Form1" >
   <mobile:List runat="server" id="List1" />
   <mobile:command runat=server OnClick="cmd1_OnClick" 
      Text="Change Properties"/><br/><br/>&nbsp;
   <mobile:command runat=server OnClick="cmd2_OnClick" 
      Text="Reset Properties"/>
</mobile:Form>

See Also

OnClick Method

Command Class