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
    Registered:
    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:

    menu.aspx:

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

    <!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div>
            <telerik:RadMenu ID="RadMenu1" runat="server" Width="568px">
                <Items>
                    <telerik:RadMenuItem Text="File" AccessKey="F">
                        <Items>
                            <telerik:RadMenuItem Text="New" AccessKey="w">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Open" AccessKey="O">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem IsSeparator="True">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Save" AccessKey="S">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Save As" AccessKey="A">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem IsSeparator="True">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Print Preview" AccessKey="V">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Print" AccessKey="P">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem IsSeparator="True">
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Close" AccessKey="C">
                            </telerik:RadMenuItem>
                        </Items>
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadMenu>   
        </div>
        </form>
    </body>
    </html>



    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.

    Regards
    Luc
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    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,
    Pepi
    the Telerik team

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