Skip to main content

ASPxClientMenuBase.GetItemCount Method

Returns the number of menu items at the root menu level.

Declaration

GetItemCount(): number

Returns

Type Description
number

The number of root menu items.

Remarks

Use the ASPxClientMenuBase.GetItemCount method to get the number of root menu items in the ASPxMenuBase.Items collection.

Decrement the return value of this method by one to get the upper available value that you can pass to the ASPxClientMenuBase.GetItem method.

Note

This method returns an incorrect value if the EnableClientSideAPI property is set to false (default). Set this property to true to enable access to a control’s client-side object.

Example

This sample demonstrates how to disable sending a postback and generating the server ItemClick event for the menu items that contain sub-items. In this sample, the desired behavior is implemented by setting the e.processOnServer parameter to false within the handler of the menu client ItemClick event.

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="DevExpress.Web.v13.1" Namespace="DevExpress.Web.ASPxMenu" TagPrefix="dxm" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>
            Try clicking menu items.</p>
        <p>
            Note: Clicking a parent item (an item that has sub-items) does not fire the menu
            server-side ItemClick event.</p>
        <dxm:ASPxMenu ID="ASPxMenu1" runat="server" BorderBetweenItemAndSubMenu="HideAll"
            OnItemClick="ASPxMenu1_ItemClick" SelectParentItem="True" ShowPopOutImages="True">
            <Items>
                <dxm:MenuItem Text="Root 1">
                    <Items>
                        <dxm:MenuItem Text="Sub Item">
                            <Items>
                                <dxm:MenuItem Text="Item 1-1">
                                </dxm:MenuItem>
                                <dxm:MenuItem Text="Item 1-2">
                                </dxm:MenuItem>
                            </Items>
                        </dxm:MenuItem>
                        <dxm:MenuItem Text="Item 1-3">
                        </dxm:MenuItem>
                    </Items>
                </dxm:MenuItem>
                <dxm:MenuItem Text="Root 2">
                    <Items>
                        <dxm:MenuItem Text="Item 2-1">
                        </dxm:MenuItem>
                        <dxm:MenuItem Text="Item 2-2">
                        </dxm:MenuItem>
                        <dxm:MenuItem Text="Item 2-3">
                        </dxm:MenuItem>
                    </Items>
                </dxm:MenuItem>
            </Items>
            <ClientSideEvents ItemClick="function(s, e) {
    e.processOnServer = e.item.GetItemCount() == 0; // Prevent generating a postback for parent menu items
           }" />
        </dxm:ASPxMenu>
        <br />
        <br />
        <br />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
See Also