e.Item.Level bug?

5 posts, 0 answers
  1. Tim
    Tim avatar
    5 posts
    Member since:
    Feb 2008

    Posted 07 Feb 2008 Link to this post

    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?


  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2809 posts

    Posted 08 Feb 2008 Link to this post

    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
  3. Jeff Durrant
    Jeff Durrant avatar
    9 posts
    Member since:
    Nov 2005

    Posted 18 Apr 2008 Link to this post

    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
    1 protected void Page_Load(object sender, EventArgs e) 
    2
    3    if (!Page.IsPostBack) 
    4    { 
    5       MyMenu.LoadContentFile("~/XML/MyMenu.xml"); 
    6    } 
    7
    8  
    9 protected void MyMenu_ItemCreated(object sender, RadMenuEventArgs e) 
    10
    11    RadMenuItem item = e.Item; 
    12    string roleName = item.Value; 
    13  
    14    item.Enabled = Roles.IsUserInRole(roleName); 
    15  
    16    // hide menu items based on role except for top level 
    17    if (item.Level > 0) 
    18    { 
    19       item.Visible = Roles.IsUserInRole(roleName); 
    20    } 
    21

    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.

  4. Tim
    Tim avatar
    5 posts
    Member since:
    Feb 2008

    Posted 19 Apr 2008 Link to this post

    I ended up creating a menu with css. Unfortunately I didn't have time to get back to Telerik.
  5. Luke Edwards
    Luke Edwards avatar
    1 posts
    Member since:
    Mar 2008

    Posted 23 Apr 2008 Link to this post

    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;
    1 Protected Sub RadMenu1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemCreated  
    2           
    3     If e.Item.Level = 0 Then 
    4         e.Item.Width = New Unit("100%")  
    5     End If 
    6  
    7 End Sub 

    Got around it by using;
     
    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 
            e.Item.Width = New Unit("100%")  
            'im at level 0, aka root...  
        Else 
            'im a sub menu item...  
        End If 
     
    End Sub 
     

     

Back to Top