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

Click Event on RadMenu

15 Answers 1300 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Amit Lamba
Top achievements
Rank 1
Amit Lamba asked on 20 Jun 2008, 06:00 PM

Hi Telerik Team,

i am using radmenu in Master page.
when i try to click the radmenu item ,i am not able to fire the click event on radmenu.

i searched some forums in telerik in which the people were saying set the Autopostback property to True.

when i try to set the autopostback property ,that property is not showing in property box of radmenu control.

means i am not able to find the autopost back property in control.

Can you pls provide the solution for this issue.

15 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 23 Jun 2008, 09:22 AM
Hi Amit Lamba,

There are two reasons for not getting the OnItemClick event fired:
  • You have not subscribed to the OnItemClick event.
<telerik:RadMenu ID="RadMenu1"   
    runat="server"   
    OnItemClick="RadMenu1_ItemClick">  
 
protected void RadMenu1_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)  
{  
    Response.Write("You clicked: " + e.Item.Text);  

  • You have set the NavigateUrl property of the menu item. This effectively disables PostBacks (OnItemClick event) because the item navigate to the particular URL rather than posting back. 
    One of the possible solutions is to subscribe to the ItemDataBound / ItemCreated events and set the NavigateUrl property to an empty string. You should, however, store the NavigateUrl property somewhere
    (e.g. in the Value or Attributes[] properties) so you can use it later to navigate after handling ItemClick events.

    Here is a simple code snippet:

protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)     
{     
    e.Item.Attributes["NavigateUrl"] = e.Item.NavigateUrl;     
    e.Item.NavigateUrl = "";     
}     
    
protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e)     
{     
    //Custom code here       
        
    //Navigate     
    Response.Redirect(e.Item.Attributes["NavigateUrl"].ToString());     
}     
 

I hope this helps.


Best wishes,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
aabdan
Top achievements
Rank 1
answered on 07 Oct 2008, 08:44 AM
i have same as you explain
and i use this code but not solve my problem?!
0
Veselin Vasilev
Telerik team
answered on 07 Oct 2008, 08:46 AM
Hi LPW,

Please explain in more detail your scenario or better - send us a sample project.

Thanks

Best wishes,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
aabdan
Top achievements
Rank 1
answered on 08 Oct 2008, 06:12 AM
Hi Veselin Vasilev,
i use a simple menu with specify a navigation url
the problem after follow your instractions 1 and 2

When i try to click the radmenu item ,i am not able to fire the click event on radmenu.


The Menu

 

<telerik:RadMenu Style="left: 100px; top: -116px;" ID="Telerik2RedMenu" runat="server"

 

 

OnItemClick="Telerik2RedMenu_ItemClick" OnClientItemClicked="onClicking">

 

 

<CollapseAnimation Duration="200" Type="OutQuint" />

 

 

<Items>

 

 

<telerik:RadMenuItem runat="server" Text="Incoming">

 

 

<Items>

 

 

<telerik:RadMenuItem runat="server" Text="Incoming" NavigateUrl="Income/Income.aspx">

 

 

</telerik:RadMenuItem>

 

 

</Items>

 

 

</telerik:RadMenuItem>

 

 

<telerik:RadMenuItem runat="server" Text="Outgoing">

 

 

<Items>

 

 

<telerik:RadMenuItem runat="server" Text="Outgoing" NavigateUrl="Outgoing.aspx">

 

 

</telerik:RadMenuItem>

 

 

</Items>

 

 

</telerik:RadMenuItem>

 

 

<telerik:RadMenuItem runat="server" Text="Setup">

 

 

<Items>

 

 

<telerik:RadMenuItem runat="server" Text="Managements" NavigateUrl="Setup/Managements.aspx">

 

 

</telerik:RadMenuItem>

 

 

</Items>

 

 

</telerik:RadMenuItem>

 

 

</Items>

 

 

</telerik:RadMenu>

and The VB Code




 

 

Protected Sub Telerik2RedMenu_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles Telerik2RedMenu.ItemClick

 

lblPageTitle.Text = e.Item.Text

Page.Header.Title = lblPageTitle.Text

Response.Redirect(e.Item.Attributes(

"NavigateUrl").ToString())

 

 

End Sub

 

 

 

 

 

Protected Sub Telerik2RedMenu_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles Telerik2RedMenu.ItemCreated

 

 

If e.Item.NavigateUrl <> "" Then

 

 

 

 

e.Item.Attributes(

"NavigateUrl") = e.Item.NavigateUrl

 

e.Item.NavigateUrl =

""

 

 

 

 

 

End If

 

 

 

 

 

End Sub

 

0
Veselin Vasilev
Telerik team
answered on 09 Oct 2008, 02:25 PM
Hello LPW,

I ran your code and the ItemClick event gets fired.
Please find attached my test page and let me know what is different in your case.


Regards,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rod
Top achievements
Rank 1
answered on 09 Oct 2008, 08:48 PM
Hi Veselin,

I'm having the same issue and have not found a solution to this problem yet.

I ran your code and the same problem occurs.
Whenever you have a url defined in NavigateUrl property, the click even does not fire for that menu item.

I also added NavigateUrl values for the top menus in your example and the click event for those also did not work.

Any help would be appreciated.

Rod
0
Rod
Top achievements
Rank 1
answered on 09 Oct 2008, 10:25 PM
I changed the menu to be dynamically generated from an xml file so the itemdatabound event would fire (and it's better design anyway) and now everything works beautifully.

I implemented the code you suggested in the ItemClick and ItemDataBound events to persist the NavigateUrl property value.

The only thing I lost from all this is that now the selected menu doesn't stay selected after I change pages.

Thanks for any help,

Rod
0
Rod
Top achievements
Rank 1
answered on 09 Oct 2008, 10:44 PM
I removed the item.HighlightPath method I had in the Load event of the page and placed it as such in the ItemDataBound event and it works great now.

string path = Request.Url.PathAndQuery;

            if (e.Item.NavigateUrl.Contains(path.Substring(path.LastIndexOf("/"))))
                e.Item.HighlightPath();

Cheers,

Rod



0
aabdan
Top achievements
Rank 1
answered on 11 Oct 2008, 10:24 AM
Hi telerik,

the code is same but my page does not work
i made workaround by make the code in page load and check the clicked item.

Best Regards,
Ahmad
0
Veselin Vasilev
Telerik team
answered on 13 Oct 2008, 07:12 AM
Hello guys,

I am glad that you all have found a solution to your problems.

Best wishes,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Craig Mellon
Top achievements
Rank 1
answered on 07 Dec 2008, 11:50 PM
In my Master Page I have a Menu.
<telerik:RadMenu ID="Navmenu" runat="server" CssClass="nav" Skin="Telerik" Flow="Horizontal"
                            OnItemClick="Navmenu_ItemClick">
        </telerik:RadMenu>

I create the Menu Dynamically.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then

            Dim user As eTech.SmartSurvey.Security.SmartSurveyPrincipal = CType(Session("CslaPrincipal"),  _
            eTech.SmartSurvey.Security.SmartSurveyPrincipal)

            If user.IsInRole("InstructionSourceOperator") Then
                lblUserRole.Text = "InstructionSourceOperator"
               CreateInstructionSourceOperatorMenu()
              
            ElseIf user.IsInRole("InstructionSourceAdministrator") Then
                lblUserRole.Text = "InstructionSourceAdministrator"

            ElseIf user.IsInRole("PanelOperator") Then
                lblUserRole.Text = "PanelOperator"
                CreatePanelOperatorMenu()
             
            ElseIf user.IsInRole("PanelAdministrator") Then
                lblUserRole.Text = "PanelAdministrator"

            ElseIf user.IsInRole("PanelSurveyor") Then
                lblUserRole.Text = "PanelSurveyor"
                CreatePanelSurveyorMenu()
              
            End If

            Dim item As RadMenuItem = Navmenu.FindItemByUrl(Request.Url.PathAndQuery)
            If item IsNot Nothing Then
                item.HighlightPath()
            End If
        End If

    End Sub

Private Sub CreatePanelOperatorMenu()
        Dim item1 As New RadMenuItem()
        item1.Text = "Home"
        Dim item2 As New RadMenuItem()
        item2.Text = "Instructions"
        Dim item3 As New RadMenuItem()
        item3.Text = "Add Instructions"
        Dim item4 As New RadMenuItem()
        item4.Text = "Surveyors"
        Dim item5 As New RadMenuItem()
        item5.Text = "Reports"
        With Navmenu.Items
            .Add(item1)
            .Add(item2)
            .Add(item3)
            .Add(item4)
            .Add(item5)
        End With
    End Sub

    Private Sub CreateInstructionSourceOperatorMenu()
        Dim item1 As New RadMenuItem()
        item1.Text = "Home"
        Dim item2 As New RadMenuItem()
        item2.Text = "Instructions"
        Dim item3 As New RadMenuItem()
        item3.Text = "Add Instructions"
        With Navmenu.Items
            .Add(item1)
            .Add(item2)
            .Add(item3)
        End With
    End Sub

    Private Sub CreatePanelSurveyorMenu()
        Dim item1 As New RadMenuItem()
        item1.Text = "Home"
        Dim item2 As New RadMenuItem()
        item2.Text = "View Diary"
        Dim item3 As New RadMenuItem()
        item3.Text = "Instructions"
        With Navmenu.Items
            .Add(item1)
            .Add(item2)
            .Add(item3)
        End With
    End Sub



Protected Sub Navmenu_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles Navmenu.ItemClick

        Dim user As eTech.SmartSurvey.Security.SmartSurveyPrincipal = CType(Session("CslaPrincipal"),  _
            eTech.SmartSurvey.Security.SmartSurveyPrincipal)

        e.Item.BackColor = Drawing.Color.Transparent

        If user.IsInRole("PanelOperator") Then
            Select Case Navmenu.Items(e.Item.Index).Text
                Case "Home"
                    Dim ItemClicked As Telerik.Web.UI.RadMenuItem = Navmenu.FindItemByText("Surveyors")
                    ItemClicked.BackColor = Drawing.Color.White
                    e.Item.NavigateUrl = "Default.aspx"
                Case "Instructions"
                    e.Item.BackColor = Drawing.Color.White
                    e.Item.NavigateUrl = "Instructions.aspx"
                Case "Add Instructions"
                    e.Item.BackColor = Drawing.Color.White
                    e.Item.NavigateUrl = "AddNewInstruction.aspx"
                Case "Surveyors"
                    e.Item.CssClass = "rmFocused"
                    e.Item.BackColor = Drawing.Color.White
                    e.Item.NavigateUrl = "Surveyors.aspx"
                Case "Reports"
                    Dim ItemClicked As Telerik.Web.UI.RadMenuItem = Navmenu.FindItemByText("Reports")
                    e.Item.BackColor = Drawing.Color.White
                    e.Item.NavigateUrl = "Reports.aspx"
            End Select
        ElseIf user.IsInRole("InstructionSourceOperator") Then
            Select Case Navmenu.Items(e.Item.Index).Text
                Case "Home"
                    Navmenu.Items(e.Item.Index).BackColor = Drawing.Color.White
                    Navmenu.Items(e.Item.Index).NavigateUrl = "InstructionSourceDefault.aspx"
                Case "Instructions"
                    Navmenu.Items(e.Item.Index).BackColor = Drawing.Color.White
                    Navmenu.Items(e.Item.Index).NavigateUrl = "InstructionSourceInstructions.aspx"
                Case "Add Instructions"
                    Navmenu.Items(e.Item.Index).BackColor = Drawing.Color.White
                    Navmenu.Items(e.Item.Index).NavigateUrl = "InstructionSourceAddInstruction.aspx"
            End Select
        ElseIf user.IsInRole("PanelSurveyor") Then
            Select Case Navmenu.Items(e.Item.Index).Text
                Case "Home"
                    Navmenu.Items(e.Item.Index).BackColor = Drawing.Color.White
                    Navmenu.Items(e.Item.Index).NavigateUrl = "SurveyorDefault.aspx"
                Case "View Diary"
                    Navmenu.Items(e.Item.Index).BackColor = Drawing.Color.White
                    Navmenu.Items(e.Item.Index).NavigateUrl = "SurveyorDiary.aspx"
                Case "Instructions"
                    Navmenu.Items(e.Item.Index).BackColor = Drawing.Color.White
                    Navmenu.Items(e.Item.Index).NavigateUrl = "SurveyorInstructions.aspx"
            End Select
        End If

        'e.Item.HighlightPath()
        'e.Item.BackColor = Drawing.Color.White
    End Sub

Now the BackColor of the Selected Item does turn White after selecting it, then If I click on another Item the previously clicked item still
has a background of white. How can I get this to work the way it should?
Basically I want to apply a style to the Selected Item. I have even tried doing e.Item.CssClass = "rmFocused" but that style doesn't even get applied. I have put the style into my Stylesheet.css file.

.RadMenu_Telerik .rmItem .rmFocused
{
    background: #fff;
}

I have looked at your example and the only thing that's different is the fact that you have declaratively created the menu and I'm dynamically creating it. Please help.

0
Veselin Vasilev
Telerik team
answered on 10 Dec 2008, 12:42 PM
Hello Craig Mellon,

You are setting the NavigateUrl property of the menu items so the next time an item is clicked - it redirects instead of firing again the NodeClick event.

As for the CssClass property, have you tried:

e.Item.CssClass += " rmFocused" 

I hope this helps.

Regards,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Patrick Williams
Top achievements
Rank 1
answered on 27 May 2010, 09:16 PM
Hi All,

The information provided below was very helpful. Can anyone help me with getting the DatafieldID from the radmenu through javascript and code behind.

Regards,
Patrick.
0
Reshmaa
Top achievements
Rank 1
answered on 18 Jun 2014, 05:08 AM
Hi Telerik Team,

Can anyone help me out for my issue....
How can i show sub menu on mouse over when tab index is change in Radmenu?

Thanks in Advance
Regards
Reshmaa Ramamurthy
0
Princy
Top achievements
Rank 2
answered on 30 Jul 2014, 10:21 AM
Hi Reshma

I suppose what you want is to focus on the particular menu item with keyboard navigation.
Check the following demo which tells about your requirement

Menu - Keyboard Support

Thanks
Princy
Tags
Menu
Asked by
Amit Lamba
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
aabdan
Top achievements
Rank 1
Rod
Top achievements
Rank 1
Craig Mellon
Top achievements
Rank 1
Patrick Williams
Top achievements
Rank 1
Reshmaa
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or