RadContextMenu Cancel Postback from OnContextMenuClick javascript event

2 posts, 1 answers
  1. Tuhin Ghosh
    Tuhin Ghosh avatar
    8 posts
    Member since:
    May 2010

    Posted 19 Jul 2011 Link to this post

    Hi,

    I have created following context menu:

    <telerik:RadContextMenu OnClientShowing="OnContextMenuShowing" OnClientItemClicked="OnContextMenuClick"
                      ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick" EnableRoundedCorners="true"
                      EnableShadows="true">
                      <Items>
                        <telerik:RadMenuItem Text="Copy" />
                        <telerik:RadMenuItem Text="Cut" />
                        <telerik:RadMenuItem Text="Paste Above" />
                        <telerik:RadMenuItem Text="Paste Below" />
                      </Items>
                    </telerik:RadContextMenu>


    OnContextMenuClick I am writing some validation and I want to cancel the postback if validations fails, but its not happening.

    I have searched everywhere but did not find any suitable answers for this , many places I found the following statement but it is not working 

    args.set_cancel(true);

    args in OnContextMenuClick does not have set_cancel method.

    Also tried with return false; that too not worked.

    Please help me by providing solutions its urgent.


    Thanks & Regards
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Jul 2011 Link to this post

    Hello Tuhin,

    You cannot cancel the OnClientItemClicked event so try the same in OnClientItemClicking and cancel the event.
    Javascrupt:
    <script type="text/javascript">
        function OnClientItemClicking(sender, args)
         {
            var item = args.get_item();
            if (item.get_text() == "Cut")
            {
                args.set_cancel(true);
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top