Hi I'm using the beta version of the menu and I'm getting a "{"Unable to cast object of type 'Telerik.Web.UI.RadMenu' to type 'Telerik.Web.UI.RadMenuItem'."}" error whenever I try to access the Level property. I don't know where to reprot beta issues, so here it is. This is what my code looks like...
If
Not e.Item.Level = 0 Then
No way it's me right?
4 Answers, 1 is accepted
0
Hello Tim,
Unfortunately, we were not able to reproduce the bug locally. Can you please send us a simple page that demonstrates the issue?
Best wishes,
Tsvetomir Tsonev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Unfortunately, we were not able to reproduce the bug locally. Can you please send us a simple page that demonstrates the issue?
Best wishes,
Tsvetomir Tsonev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Jeff Durrant
Top achievements
Rank 1
answered on 18 Apr 2008, 08:57 PM
I'm getting the same error with version 2008.1.415.20 of Telerik.Web.UI.dll
MyPage.ASPX
<telerik:RadMenu ID="MyMenu" runat="server" OnItemCreated="MyMenu_ItemCreated" /> |
MyPage.ASPX.CS
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (!Page.IsPostBack) | |
{ | |
MyMenu.LoadContentFile("~/XML/MyMenu.xml"); | |
} | |
} | |
protected void MyMenu_ItemCreated(object sender, RadMenuEventArgs e) | |
{ | |
RadMenuItem item = e.Item; | |
string roleName = item.Value; | |
item.Enabled = Roles.IsUserInRole(roleName); | |
// hide menu items based on role except for top level | |
if (item.Level > 0) | |
{ | |
item.Visible = Roles.IsUserInRole(roleName); | |
} | |
} |
MyMenu.XML
<?xml version="1.0" encoding="utf-8" ?> |
<Menu> |
<Group Flow="Horizontal"> |
<Item Text="Page1" ToolTip="Page1" NavigateUrl="~/MyPage1.aspx" Value="MyRole1"> |
<Group> |
<Item Text="Page 1a" NavigateUrl="~/MyPage1a.aspx" PostBack="true" Value="MyRole1a"/> |
<Item Text="Page 1b" NavigateUrl="~/MyPage1a.aspx" PostBack="true" Value="MyRole1b"/> |
</Group> |
</Item> |
<Item Text="Page2" ToolTip="Page2" NavigateUrl="~/MyPage2.aspx" Value="MyRole2"> |
<Group> |
<Item Text="Page 2a" NavigateUrl="~/MyPage2a.aspx" PostBack="true" Value="MyRole2a"/> |
<Item Text="Page 2b" NavigateUrl="~/MyPage2a.aspx" PostBack="true" Value="MyRole2b"/> |
</Group> |
</Item> |
</Group> |
</Menu> |
item.Level > 0
That line throws the exception mentioned by the original poster.
0
Tim
Top achievements
Rank 1
answered on 19 Apr 2008, 11:55 AM
I ended up creating a menu with css. Unfortunately I didn't have time to get back to Telerik.
0
Luke Edwards
Top achievements
Rank 1
answered on 23 Apr 2008, 11:34 AM
I am [was] also getting this same error "Unable to cast object of type 'Telerik.Web.UI.RadMenu' to type 'Telerik.Web.UI.RadMenuItem'". With version 2008.1.415.
Line 3 of this code will throw the error;
Got around it by using;
Line 3 of this code will throw the error;
Protected Sub RadMenu1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemCreated | |
If e.Item.Level = 0 Then | |
e.Item.Width = New Unit("100%") | |
End If | |
End Sub |
Got around it by using;
Protected Sub RadMenu1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemCreated |
If TypeOf e.Item.Parent Is Telerik.Web.UI.RadMenu Then |
e.Item.Width = New Unit("100%") |
'im at level 0, aka root... |
Else |
'im a sub menu item... |
End If |
End Sub |