Click Event on RadMenu

15 posts, 0 answers
  1. Amit Lamba
    Amit Lamba avatar
    10 posts
    Member since:
    Jan 2008

    Posted 20 Jun 2008 Link to this post

    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.

  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts
    Member since:
    Jul 2012

    Posted 23 Jun 2008 Link to this post

    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

  3. LPW
    LPW avatar
    26 posts
    Member since:
    Apr 2007

    Posted 07 Oct 2008 Link to this post

    i have same as you explain
    and i use this code but not solve my problem?!

  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts
    Member since:
    Jul 2012

    Posted 07 Oct 2008 Link to this post

    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.

  5. LPW
    LPW avatar
    26 posts
    Member since:
    Apr 2007

    Posted 08 Oct 2008 Link to this post

    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

     

  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts
    Member since:
    Jul 2012

    Posted 09 Oct 2008 Link to this post

    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.

  7. Rod
    Rod avatar
    23 posts
    Member since:
    Aug 2007

    Posted 09 Oct 2008 Link to this post

    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

  8. Rod
    Rod avatar
    23 posts
    Member since:
    Aug 2007

    Posted 09 Oct 2008 Link to this post

    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

  9. Rod
    Rod avatar
    23 posts
    Member since:
    Aug 2007

    Posted 09 Oct 2008 Link to this post

    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



  10. LPW
    LPW avatar
    26 posts
    Member since:
    Apr 2007

    Posted 11 Oct 2008 Link to this post

    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

  11. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts
    Member since:
    Jul 2012

    Posted 13 Oct 2008 Link to this post

    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.

  12. Craig Mellon
    Craig Mellon avatar
    53 posts
    Member since:
    May 2005

    Posted 07 Dec 2008 Link to this post

    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.

  13. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts
    Member since:
    Jul 2012

    Posted 10 Dec 2008 Link to this post

    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.

  14. Patrick Williams
    Patrick Williams avatar
    8 posts
    Member since:
    Aug 2009

    Posted 27 May 2010 Link to this post

    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.

  15. Reshmaa
    Reshmaa avatar
    4 posts
    Member since:
    Jun 2014

    Posted 18 Jun Link to this post

    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

Back to Top