More in this section

Forums / Developing with Sitefinity / Unable to cast object of type 'Telerik.Web.UI.RadMenu'

Unable to cast object of type 'Telerik.Web.UI.RadMenu'

2 posts, 0 answered
  1. Luc Baeten
    Luc Baeten avatar
    169 posts
    23 Sep 2005
    31 Oct 2008
    Link to this post
    Hello Telerik Team

    I installed the new version of Sitefinity 3.5 SP1 (3_5_1747) and trying to migrate a 3.1 site to this new version.

    In this site I am using the RadMenu control but the used code results in the error: Unable to cast object of type 'Telerik.Web.UI.RadMenu' to type 'Telerik.Web.UI.RadMenuItem'.

    I created a simple test page in which I also have the same problem:


    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="menu.aspx.vb" Inherits="menu" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <html xmlns="">
    <head runat="server">
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <telerik:RadMenu ID="RadMenu1" runat="server" Width="568px">
                    <telerik:RadMenuItem Text="File" AccessKey="F">
                            <telerik:RadMenuItem Text="New" AccessKey="w">
                            <telerik:RadMenuItem Text="Open" AccessKey="O">
                            <telerik:RadMenuItem IsSeparator="True">
                            <telerik:RadMenuItem Text="Save" AccessKey="S">
                            <telerik:RadMenuItem Text="Save As" AccessKey="A">
                            <telerik:RadMenuItem IsSeparator="True">
                            <telerik:RadMenuItem Text="Print Preview" AccessKey="V">
                            <telerik:RadMenuItem Text="Print" AccessKey="P">
                            <telerik:RadMenuItem IsSeparator="True">
                            <telerik:RadMenuItem Text="Close" AccessKey="C">

    and the very simple  code behind menu.aspx.vb:

    Partial Class menu
        Inherits System.Web.UI.Page

        Protected Sub RadMenu1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemCreated
            If e.Item.Level = 0 Then

            End If
        End Sub
    End Class

    When I run this menu.aspx in my browser I get the error on the line with
        If e.Item.Level = 0 Then

    I have debugged the code. The first time I entered the Radmenu1_ItemCreated procedure the value of e.item.level is the same as the error mentioned above.
    Hope you can help with this problem.

  2. Pepi
    Pepi avatar
    981 posts
    31 Jan 2017
    03 Nov 2008
    Link to this post
    Hello Luc,

    Please use the following to check if the level of the current item is 0:

    Protected Sub RadMenu1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemCreated 
            If TypeOf e.Item.Parent Is Telerik.Web.UI.RadMenu Then 
            End If 
    End Sub 

    Hope this helps.

    All the best,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered