blockConfirm on RadMenuItemClicking event

5 posts, 2 answers
  1. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 26 Jul 2010 Link to this post

    I am using a context menu and when a user clicks on a certain menuitem I want a confirm dialog to appear asking whether or not it should proceed with the onclick event. If the user wants to proceed, then the onclick event is triggered, if the user does not, then nothing happens and the confirm dialog just closes. I have tried this using the blockConfirm as shown:
    window.blockConfirm = function (text, mozEvent, oWidth, oHeight, callerObj, oTitle)
    {
      var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually
      //Cancel the event
      ev.cancelBubble = true;
      ev.returnValue = false;
      if (ev.stopPropagation) ev.stopPropagation();
      if (ev.preventDefault) ev.preventDefault();
     
      //Determine who is the caller
      var callerObj = ev.srcElement ? ev.srcElement : ev.target;
     
      //Call the original radconfirm and pass it all necessary parameters
      if (callerObj)
      {
        //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.
        var callBackFn = function (arg)
        {
          if (arg)
          {
            callerObj["onclick"] = "";
            if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz
            else if (callerObj.tagName == "A") //We assume it is a link button!
            {
              try
              {
                eval(callerObj.href)
              }
              catch (e)
              {
              }
            }
          }
        }
        radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
      }
      return false;
    }
    function RadContextMenu_ItemClicking(sender, eventArgs)
    {
      var item = eventArgs.get_item();
        if (item.get_text().substring(0, 7).toLowerCase() == "publish")
        {
            //display radconfirm popup
            return blockConfirm('message', eventArgs, 340, 100, '', 'Confirm Publish');
        }
      if (item.get_text().substring(0, 7).toLowerCase() == "version" || item.get_text().substring(0, 7).toLowerCase() == "publish")
      
        eventArgs.set_cancel(true);
      }
      else
      {
        //disable all context menus
        <asp:Literal ID="LiteralDisableContextMenu" runat="server" />
      }
    }

    I am pretty sure the problem is with the eventArgs variable that I am sending the blockConfirm. I have the blockConfirm working on a different part of my project when triggered from an ImageButton and that call is:

    return blockConfirm('Are you sure you want to delete this item?', event, 340, 100, '', 'Confirm Delete?');

    When I try using the variable "event" with the onclientclicking I get an error saying it does not exist. So what do I need to do to make this work with a RadMenuItem?

    I read on the forums and could not find any answer, however this has been asked before here: http://www.telerik.com/community/forums/aspnet-ajax/treeview/radconfirm-on-radtreeview-nodeclick.aspx







  2. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 29 Jul 2010 Link to this post

    No-one has a solution for this?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 30 Jul 2010 Link to this post

    Hello Dan Miller,

    Please accept my appologies for the late answer.

    You'll have to use the eventArgs.get_domEvent() instead of eventArgs to be able to work with the event.

    Hope this helps.

    All the best,
    Veronica Milcheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 05 Aug 2010 Link to this post

    Thanks that did the trick! However now I have a new problem. The blockConfirm is not stopping the ajax refresh that occurs when I click on a menu item. It shows up but does the ajax refresh regardless of whether I click "confirm" or "cancel".
    function RadContextMenu_ItemClicking(sender, eventArgs)
    {
      var item = eventArgs.get_item();
      var
    mySplit = item.get_value().split(',');
      var publishDate = new Date(mySplit[1]);
      var now = new Date();
      //display radconfirm popup
      if(publishDate > now)
      return blockConfirm('Are you sure you want to publish \"<strong>' + mySplit[0] + '</strong>\"? This          content is currently set to be active ' + mySplit[1] + '.', eventArgs.get_domEvent(), 340, 100, '',        'Confirm Publish');
    }
    This is the ItemClicking event of the contextmenu. If you need any other code snippets please let me know.
  6. Answer
    Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 06 Aug 2010 Link to this post

    Hello Dan,

    You're return line should be replaced with a call to eventArgs.set_cancel(blockConfirm()), in order to stop the click event from happening.

    I hope that helps.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017