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

Menu Item On Click not firing

2 Answers 170 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 12 Apr 2012, 08:22 PM

I have a rad menu with several items.  The menu items lead to different places depending on a few things, so i'm trying to implement an OnClick handler in the code behind to redirect appropriately.  I've tried all kinds of combinations and scoured the forums and nothing has worked so far.  

   My OnClick method is just a stub right now with a breakpoint so I can see when it gets called, only it isn't getting called, and I'm redirected to the default.aspx page. 

Ths is within a user control, if that matters.  Are you aware of anything that could cause this behavior? 

protected void RadMenu_ItemClick(object sender, RadMenuEventArgs e)
        {
            int i = 0;
            String s = e.Item.Value;
        }

<radM:RadMenu ID="RadMenu" runat="server"  OnItemClick="RadMenu_ItemClick" >
    <Items>
         <radM:RadMenuItem runat="server" ID="sampleItem" Text="Click Me" />
    </Items>
</radM:RadMenu>

2 Answers, 1 is accepted

Sort by
0
Cat Cheshire
Top achievements
Rank 1
answered on 16 Apr 2012, 11:41 AM
0
Phil
Top achievements
Rank 2
answered on 24 Apr 2012, 01:07 AM
Hi:

Re-iterate your UI:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="RadMenu2.aspx.cs" Inherits="Telerik.RadMenu.RadMenu2" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <telerik:RadMenu ID="RadMenu1" runat="server" onitemclick="RadMenu1_ItemClick" >
        <Items>
            <telerik:RadMenuItem  runat="server" ID="sampleItem1" Text="Home" />
            <telerik:RadMenuItem  runat="server" ID="sampleItem2" Text="Click Me" />
        </Items>
    </telerik:RadMenu>
</asp:Content>

Code behind:
namespace Telerik.RadMenu
{
    public partial class RadMenu2 : System.Web.UI.Page
    {
        protected void RadMenu1_ItemClick(object sender, Web.UI.RadMenuEventArgs e)
        {
            int _i = 1;
        }
    }
}

In Immediate window:
?e.Item
{Telerik.Web.UI.RadMenuItem}
    base {Telerik.Web.UI.NavigationItem}: {Telerik.Web.UI.RadMenuItem}
    ClickedCssClass: "rmClicked"
    ClickedImageUrl: ""
    DataItem: null
    DisabledCssClass: "rmDisabled"
    DisabledImageUrl: ""
    EnableImageSprite: false
    ExpandedCssClass: "rmExpanded"
    ExpandedImageUrl: ""
    ExpandMode: ClientSide
    FocusedCssClass: "rmFocused"
    GroupSettings: {Auto,Vertical,0,0,,}
    HoveredImageUrl: ""
    ImageUrl: ""
    IsSeparator: false
    Items: {Telerik.Web.UI.RadMenuItemCollection}
    ItemTemplate: null
    Level: 0
    Menu: {Telerik.Web.UI.RadMenu}
    NavigateUrl: ""
    OuterCssClass: ""
    Owner: {Telerik.Web.UI.RadMenu}
    PostBack: true
    Selected: true
    SelectedCssClass: "rmSelected"
    SelectedImageUrl: ""
    Target: ""
    Text: "Click Me"
    Value: ""
I think you are looking for Text not value, mine fired.
You can do a case statement on Text, etc.
switch( e.Item.Text.ToLower())
{
    case "home":
        int _i = 1;
        break;
    case "click me":
        int _j = 1;
        break;
    default:
        break;
}

Phil
Tags
Menu
Asked by
Aaron
Top achievements
Rank 1
Answers by
Cat Cheshire
Top achievements
Rank 1
Phil
Top achievements
Rank 2
Share this question
or