This is a migrated thread and some comments may be shown as answers.

OnClientItemClicked VS OnClientItemClicking events

3 Answers 68 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Veronika
Top achievements
Rank 1
Veronika asked on 10 Mar 2013, 03:37 PM
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 ?




3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Mar 2013, 04:33 AM
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.

0
ido nahmias
Top achievements
Rank 1
answered on 20 Mar 2013, 09:28 AM
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!

0
Princy
Top achievements
Rank 2
answered on 21 Mar 2013, 06:15 AM
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.

Tags
General Discussions
Asked by
Veronika
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
ido nahmias
Top achievements
Rank 1
Share this question
or