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

RadMenu with ajaxRequestWithTarget

5 Answers 118 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 2
Sergey asked on 08 Nov 2010, 06:12 PM
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

5 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 11 Nov 2010, 04:25 PM
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
0
Sergey
Top achievements
Rank 2
answered on 11 Nov 2010, 05:07 PM
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? 
0
Iana Tsolova
Telerik team
answered on 12 Nov 2010, 04:51 PM
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
0
Sergey
Top achievements
Rank 2
answered on 12 Nov 2010, 06:14 PM
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.


0
Iana Tsolova
Telerik team
answered on 15 Nov 2010, 01:19 PM
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
Tags
Ajax
Asked by
Sergey
Top achievements
Rank 2
Answers by
Iana Tsolova
Telerik team
Sergey
Top achievements
Rank 2
Share this question
or