BulletedList.OnClick Method

Raises the Click event for the BulletedList control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

protected:
virtual void OnClick (
	BulletedListEventArgs^ e
)
protected void OnClick (
	BulletedListEventArgs e
)
protected function OnClick (
	e : BulletedListEventArgs
)
Not applicable.

Parameters

e

A BulletedListEventArgs that contains the event data.

The Click event is raised when a list item in the BulletedList control is clicked. To enable list items in a BulletedList control to raise the Click event, you must first set the DisplayMode property to the value LinkButton.

Raising an event invokes the event handler through a delegate. For more information, see Consuming Events.

The OnClick method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors: When overriding the OnClick method in a derived class, be sure to call the OnClick method for the base class so that registered delegates receive the event.

The following code example demonstrates how to specify and code an event handler for the Click event of a BulletedList control. When a list item is clicked, a message is displayed in a Label control on the page.

<%@ Page Language="VB" %>

<!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 runat="server">
    <title>BulletedList Click Example</title>
<script runat="server">

        Sub ItemsBulletedList_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.BulletedListEventArgs)
            ' Change the message displayed in the label based on the index
            ' of the list item that was clicked.
            Select Case (e.Index)
                Case 0
                    Message.Text = "You clicked list item 1."
                Case 1
                    Message.Text = "You clicked list item 2."
                Case 2
                    Message.Text = "You clicked list item 3."
                Case Else
                    Throw New Exception("You did not click a valid list item.")
            End Select

        End Sub

    </script>

</head>
<body>

    <h3>BulletedList Click Example</h3>

    <form id="form1" runat="server">
            
        <p>Click on an item in the list to raise the Click event.</p> 
        
        <asp:BulletedList id="ItemsBulletedList" 
            BulletStyle="Disc"
        DisplayMode="LinkButton" 
        OnClick="ItemsBulletedList_Click"
        runat="server">    
            <asp:ListItem Value="http://www.cohowinery.com">Coho Winery</asp:ListItem>
        <asp:ListItem Value="http://www.contoso.com">Contoso, Ltd.</asp:ListItem>
        <asp:ListItem Value="http://www.tailspintoys.com">Tailspin Toys</asp:ListItem>
    </asp:BulletedList>
            
    <asp:Label id="Message" 
        Font-Size="12"
        Width="168px" 
        Font-Bold="True" 
        runat="server"
        AssociatedControlID="ItemsBulletedList"/>
              
   </form>

</body>
</html>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: