OnClientItemClicked VS OnClientItemClicking events

4 posts, 0 answers
  1. Veronika
    Veronika avatar
    1 posts
    Member since:
    Mar 2013

    Posted 10 Mar 2013 Link to this post

    Can anyone explain the difference between OnClientItemClicked and OnClientItemClicking events? Seems that OnClientItemClicking has more methods to work with, for example - set_cancel,  and is preferrable than OnClientItemClicked ? why won't I always use OnClientItemClicking ?




  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Mar 2013 Link to this post

    Hello Veronika,

    You have not specified any RadControl in particular, So let me explain with regard to RadMenu.

    The OnClientItemClicking client-side event occurs when the user clicks on a menu item, before the menu responds to the mouse click.

    The event handler receives two parameters:

    1. The instance of the menu firing the event.

    2. An eventArgs parameter containing the following methods:

      • get_item returns a reference to the RadMenuItem that was clicked.

      • set_cancel lets you prevent the menu from responding to the mouse click.

      • get_cancel returns a boolean value indicating whether the mouse click was cancelled.

      • get_targetElement (RadContextMenu only) returns a reference to the target element attached to the context menu that is responsible for the context menu showing.

      • get_domEvent returns a reference to the DOM event that caused the clicking.

        You can use this event to pre-process an item click or to cancel the default response.

        JavaScript:

        <script type="text/javascript">
        function onClicking(sender, eventArgs) {
            var item = eventArgs.get_item();
            var navigateUrl = item.get_navigateUrl();
            if (navigateUrl && navigateUrl != "#") {
                var proceed = confirm("Navigate to " + navigateUrl + " ?");
                if (!proceed) {
                    eventArgs.set_cancel(true);
                }
                else {
                    eventArgs.set_cancel(false);
                }
            }
        }
        </script>


    The OnClientItemClicked client-side event occurs when the user clicks on a menu item, after the menu responds to the mouse click.

    The event handler receives two parameters:

    1. The instance of the menu firing the event.

    2. An eventArgs parameter containing the following methods:

      • get_item returns a reference to the RadMenuItem that was clicked.

      • get_targetElement (RadContextMenu only) returns a reference to the target element attached to the context menu that is responsible for the context menu showing.

      • get_domEvent returns a reference to the DOM event that caused the clicking.

        You can use this event to respond when the user clicks on a menu item:

        JavaScript:

        <script type="text/javascript">
            var clipboardEmpty = true;
            function copyPasterItemClicked(sender, args) {
                var clipboardElement = $get("hdClipboard");
                var itemValue = args.get_item().get_value();
                if (itemValue == "Cut") {
                    clipboardElement.value = args.get_targetElement().value;
                    args.get_targetElement().value = "";
                    clipboardEmpty = false;
                }
                if (itemValue == "Copy") {
                    clipboardElement.value = args.get_targetElement().value;
                    clipboardEmpty = false;
                }
                else if (itemValue == "Paste") {
                    args.get_targetElement().value = clipboardElement.value;
                }
            
        </script>

        Thanks,
        Princy.

  3. ido nahmias
    ido nahmias avatar
    64 posts
    Member since:
    May 2006

    Posted 20 Mar 2013 Link to this post

    Hi,Princy! Thanks for reply!
    So what are the situations when I  OnClientItemClicked has 'advantages' before OnClientItemClicking  
    ? seems that OnClientItemClicking  has all the options that OnClientItemClicked has and some additional!

  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Mar 2013 Link to this post

    Hi,

    Its not like OnClientItemClicking has all the options that OnClientItemClicked has and some additional. Let me explain with an example. Suppose you are clicking a RadMenuItem and you are checking some conditions from client-side before navigating. If few conditions are not satisfied you want to cancel the click event. In such a scenario, you may use OnClientItemClicking. All those things you want to execute before a control responds to the mouse click event is written inside the OnClientItemClicking whereas things you want to execute after control responds to the mouse click is written in OnClientItemClicked.

    Thanks,
    Princy.

Back to Top