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

How to get selection index of radmenu using javascript

7 Answers 339 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Bharat
Top achievements
Rank 1
Bharat asked on 05 Jun 2014, 09:52 AM
Hi

I am adding a radmenu onto a page through class not through source. Now I want to access the value or selected index using javascript. I tried to accomplish this task by finding rad menu but its giving an exception that RadMenu with this id does not exists
e.g
$find("<%= RadMenu1.ClientID %>");

I can not access this neither on page nor in any javascript file.

Please let me know how to do this.

Thank
Bharat Bhushan

7 Answers, 1 is accepted

Sort by
0
Aneliya Petkova
Telerik team
answered on 09 Jun 2014, 10:09 AM
Hi Bharat,

You can obtain the reference to the client-side RadMenu object using the following JavaScript code:

var menu = $find("<%= RadMenu1.ClientID %>");
Attached you can find a very simple example.
Please also check our help articles on Client-Side programming:

Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bharat
Top achievements
Rank 1
answered on 09 Jun 2014, 12:57 PM
But the issue is that I am adding this dynamically not from design, So I am not able to find it neither from page nor from javascript
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Jun 2014, 02:53 AM
Hi Bharat,

It is not possible to directly access the dynamically created control in JavaScript. One approach is that you can pass the control id from the server side by using Attributes parameter and access it in JavaScript. In the above posted code I am passing the ID of  dynamically created RadMenu in OnClientClicked event of RadButton, and accessing it in JavaScript by using getAttribute method. Please elaborate your requirement if it doesn't help.

C#:
radbtnSelectedMenu.OnClientClicked = "GetSelectedItemIndex";
//passing id of the dynamically created RadMenu 
radbtnSelectedMenu.Attributes.Add("MenuId", Menu.ClientID);

JavaScript:
function GetSelectedItemIndex(sender, args) {
    //accessing id of the RadMenu
    var menu = document.getElementById(sender.get_id()).getAttribute("MenuId");
    var menuId = document.getElementById(menu);
}

Thanks,
Princy.
0
Accepted
Aneliya Petkova
Telerik team
answered on 10 Jun 2014, 07:56 AM
Hi Bharat,

If you create a RadMenu dynamically, the easiest way to find the menu is to declare a public string MenuClientID in the code behind and to initialize that string with the menu.ClientID. Then you could find the menu on the client-side using the following JavaScript:
var menu = $find("<%=MenuClientID%>");
I modified the project I send you in the previous thread. Please check it and let me know if this is helpful.

Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bharat
Top achievements
Rank 1
answered on 10 Jun 2014, 08:16 AM
Thanks for your support. Now I am able to get selectedindex, selectedvalue.
Thanks once again
0
A. Koster
Top achievements
Rank 1
answered on 25 Jul 2014, 11:31 AM
Hello,
      Can anyone help me out of my issue. I'm using tab key for index change in the Radmenu for that using below javascript and its working fine but for the last Radmenuitem its not getting hidie . so how can i want to change this code to getting hide???

<script language="javascript" type="text/javascript">
function OnClientItemFocus(sender, eventArgs) 
{
eventArgs.get_item().open();
}
</script>

Thanks in Advance
Regards
Reshmaa Ramamurthy.
0
Aneliya Petkova
Telerik team
answered on 29 Jul 2014, 09:59 AM
Hi Alfred,

You can use the following workaround to get the desired functionality of the RadMenu control:
<script type="text/javascript">
    function OnClientItemFocus(sender, eventArgs) {
        eventArgs.get_item().open();
    }
    function OnClientItemBlurMenu(sender, args) {
        sender.close(true);
    }
</script>

Markup:
<telerik:RadMenu ID="RadMenu1" runat="server" RenderMode="Classic" ClickToOpen="true" OnClientItemFocus="OnClientItemFocus" OnClientItemBlur="OnClientItemBlurMenu">
    <Items>
...


Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Menu
Asked by
Bharat
Top achievements
Rank 1
Answers by
Aneliya Petkova
Telerik team
Bharat
Top achievements
Rank 1
Princy
Top achievements
Rank 2
A. Koster
Top achievements
Rank 1
Share this question
or