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

Bug in Telerik.Web.UI.RadMenuItem.set_selected()

3 Answers 96 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Gunnar
Top achievements
Rank 1
Gunnar asked on 11 Sep 2009, 01:55 PM
Hi,

The following code produces the right output the first time the button is pressed.
But the second time and there after all menu items will return false when calling get_selected()

Version: Telerik.Web.UI 2009.02.0836.35

<%

@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

 

<%

@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

 

html xmlns="http://www.w3.org/1999/xhtml">

 

<

 

head runat="server">

 

 

<title></title>

 

 

<script language="javascript" type="text/javascript">

 

 

 

 

function populateContextMenu()

 

{

 

var ctxMenu = Sys.Application.findComponent('ctx');

 

ctxMenu.get_items().clear();

 

for (var i = 0; i < 10; i++)

 

{

 

var menuItem = new Telerik.Web.UI.RadMenuItem();

 

ctxMenu.get_items().add(menuItem);

menuItem.set_value(i.toString());

menuItem.set_text(i.toString());

 

 

 

 

if (i == 2)

 

{

menuItem.set_selected(

true);

 

}

Sys.Debug.trace(i.toString() +

': ' + menuItem.get_selected());

 

}

 

return false;

 

}

 

</script>

 

</

 

head>

 

<

 

body>

 

 

<form id="form1" runat="server">

 

 

<asp:ScriptManager ID="ScriptManager1" runat="server" />

 

 

<div>

 

 

 

<telerik:radcontextmenu id="ctx" runat="server" skin="Black" >

 

 

 

</telerik:radcontextmenu>

 

 

<asp:Button ID="btn" Text="Populate" runat="server" OnClientClick="populateContextMenu(); return false;" />

 

 

</div>

 

 

</form>

 

</

 

body>

 

</

 

html>

 

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 11 Sep 2009, 03:04 PM
Hi Gunnar,

You should also reset the selected item when removing all the items like this:

var ctxMenu = Sys.Application.findComponent('ctx'); 
ctxMenu._clearSelectedItem(); 
ctxMenu.get_items().clear(); 

and get_selected() method will return correct values.

All the best,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Gunnar
Top achievements
Rank 1
answered on 14 Sep 2009, 06:41 AM
Hi,

Thank's for the quick reply.

I consider this solution as a workaround.

ctxMenu._clearSelectedItem() is a private method and does not exist in the documentation. This method isn't in the public API.
ctxMenu.get_items().clear() should also clear the current selected item in the menu.
And menuItem.set_selected(true) should really set the item to selected even if a removed item is selected.

Regards

 


0
Yana
Telerik team
answered on 14 Sep 2009, 12:05 PM
Hello Gunnar,

We'll investigate this issue further, for now please use the provided solution.

Greetings,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Menu
Asked by
Gunnar
Top achievements
Rank 1
Answers by
Yana
Telerik team
Gunnar
Top achievements
Rank 1
Share this question
or