RadMenu with ajaxRequestWithTarget

6 posts, 0 answers
  1. Sergey
    Sergey avatar
    22 posts
    Member since:
    Jun 2009

    Posted 08 Nov 2010 Link to this post

    Hey, 

    I'm trying to figure out how to make ajaxManager.ajaxRequestWIthTarget function with a RadMenu.

    The issue is that there's a timed javascript function that needs to call an AJAX request with a specific item in the RadMenu. 

    The below...
    var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
    ajaxManager.ajaxRequestWithTarget('<%= ReportPageMenu.FindItemByValue("MyItemValue").UniqueID %>', '');
    doesn't accomplish the desired behaviour, the handler behind the ReportPageMenu is never hit in the code.

    <telerik:RadMenu runat="server" ID="ReportPageMenu" OnItemClick="ReportMenuHandler"/>


    What's the correct/best way to achieve a postback caused by ajaxRequestWithTarget that forces the code in the onItemClick for the RadMenu to fire off with the correct sender/args? 

    Thanks

  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 11 Nov 2010 Link to this post

    Hi Sergey,

    In order to achieve your goal try passing as first parameter of the ajaxRequestWithTarget() method the RadMenu UniqueID. And for the second parameter - the index of the RadMenuItem. Thus the OnItemClick event should be fired.

    Regards,
    Iana
    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
  3. Sergey
    Sergey avatar
    22 posts
    Member since:
    Jun 2009

    Posted 11 Nov 2010 Link to this post

    I've updated the ajaxRequestWithTarget to:

    ajaxManager.ajaxRequestWithTarget('<%= ReportPageMenu.UniqueID %>', '<%= ReportPageMenu.FindItemByValue("MyTargetValue").Index %>');

    It does correctly retrieve the Menu UniqueID, and the correct Index of my item, in this case 3, but after it still does not get to the OnItemClick or the OnClientItemClicking events of the RadMenu? 
  4. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 12 Nov 2010 Link to this post

    Hi Sergey,

    I was able to make it working on my side. Can you check the attached page and let me know if it works as  expected on your end?

    Kind regards,
    Iana
    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. Sergey
    Sergey avatar
    22 posts
    Member since:
    Jun 2009

    Posted 12 Nov 2010 Link to this post

    Just replying to leave an answer behind. 

    1. Thanks for the response and attached project Iana, it works correctly for any menu where there are no nested items. If there are nested items in the menu the sample doesn't get the non-root level items correctly. 

    2. The full solution is that the passed args need to be of format '#:#' for example for a menu where root items have one level of items under them. Where 'root_item_index:item_index_of_your_item'. This can be found by something like this method, or similar (provided by Telerik) -- keep in mind this does not account for visible/hidden/etc items, and this will break it off if you have any:
    protected string GetHierarchicalIndex(RadMenuItem item)
    {
        StringBuilder hierarchicalIndex = new StringBuilder();
      
        while(item.Parent != RadMenu1)
        {
            hierarchicalIndex.Insert(0, ":"+ item.Index);
      
            item = (RadMenuItem)item.Parent;
        }
      
        hierarchicalIndex.Insert(0, item.Index.ToString());
      
        return hierarchicalIndex.ToString();
    }

    3. The samples on this documentation page: http://www.telerik.com/help/aspnet/menu/menu_client-sideapi.html are misleading because they do not give the correct case for the client-side method calls (leading to method not found errors). The demo: http://demos.telerik.com/aspnet-ajax/menu/examples/programming/clientsideapi/defaultcs.aspx for similar functionality is however correct.


  6. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 15 Nov 2010 Link to this post

    Hello Sergey,

    Yes, you are right, I have not test the provided solution with a menu having nested items.

    However, sharing your experience and finding is appreciated and I am sure the details you provided will help other community members as well.

    Additionally, I will forward the mentioned help article to our help team for further check.


    Best wishes,
    Iana
    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
Back to Top