making Parent Menu Item no click

7 posts, 0 answers
  1. grant
    grant avatar
    7 posts
    Member since:
    May 2008

    Posted 15 Aug 2008 Link to this post

    I am using a menu control with submenus generated from database.  Is there a way to make the parent non clickable.  Right now when the parent gets clicked, the subs are displayed twice.

  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 18 Aug 2008 Link to this post

    Hello grant,

    You can subscribe to the OnClientItemClicking client-side event and cancel it if the level of the item is 0.

    <script type="text/javascript"
    function onClicking(sender, eventArgs) 
      var item = eventArgs.get_item(); 
       
      if (item.get_level() == 0) 
      { 
          eventArgs.set_cancel(true); 
      } 
    </script> 
    <telerik:RadMenu ID="RadMenu1" runat="server" 
       OnClientItemClicking="onClicking"
     


    Greetings,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. grant
    grant avatar
    7 posts
    Member since:
    May 2008

    Posted 18 Aug 2008 Link to this post

    Thanks for that, it seems to be working fine.  However when the parent item is clicked it returns an error on the page.  Is this normal or did I miss something? 

    Also is there any way to return a message to direct the user on how to properly navigate the menu?
  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 18 Aug 2008 Link to this post

    Hi grant,

    What is the error that you get?

    Please paste here all the relevant code so we can reply accordingly.

    Thanks

    Best wishes,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. grant
    grant avatar
    7 posts
    Member since:
    May 2008

    Posted 18 Aug 2008 Link to this post

    I managed to find an easy solution to the problem. 

    For the menu items that I dont want to be clickable, I simply made the Navigate URL = "#".

    Works like a charm, and is quite simple...

  6. grant
    grant avatar
    7 posts
    Member since:
    May 2008

    Posted 18 Aug 2008 Link to this post

    The menu at : http://www.atlanticportal.com/AtlanticPortal/en/NS.aspx

    Works corectly, the parents are not clickable.

    I have a different menu for http://www.atlanticportal.com/AtlanticPortal/en/NL.aspx Which is formed in exactly the same way but it generates an <a href="javascript:__doPostBack

    The vb code for both menus are as follows.:

    Working Menu:

    Imports

    System.Data.Odbc

    Imports

    System.Data

    Imports

    Telerik.WebControls

    Partial

    Class controls_SideNav

    Inherits System.Web.UI.UserControl

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

    Dim dbcommand As OdbcCommand

    Dim dbconnection As OdbcConnection

    Dim dbreader As OdbcDataReader

    Dim sql As String

    dbconnection =

    New OdbcConnection("DSN=AtlanticPortal;")

    dbconnection.Open()

    sql =

    "Select * FROM Region WHERE ProvID = " & Session("ProvId").ToString

    dbcommand =

    New OdbcCommand(sql, dbconnection)

    dbreader = dbcommand.ExecuteReader(CommandBehavior.CloseConnection)

    Dim dt As DataTable = New DataTable

    dt.Load(dbreader)

    dbconnection.Close()

    dbreader.Close()

    Dim radMenu As RadMenu

    radMenu =

    CType(Me.FindControl("RadMenuSideNav"), Telerik.WebControls.RadMenu)

    'Home

    Dim parentItem As RadMenuItem

    Dim childItem As RadMenuItem

    parentItem = radMenu.Items(0)

    Select Case Session("ProvID").ToString

    Case "1"

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/NL.aspx"

    Case "2"

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/NS.aspx"

    Case "3"

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/NB.aspx"

    Case "4"

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/PEI.aspx"

    End Select

     

    If dt.Rows.Count > 0 Then

    'Where To Stay

    parentItem = radMenu.Items(1)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/WhereToStayoth.aspx?Region=" & row("ID").ToString & "&Community=0&Category=0&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'Where To Eat

    parentItem = radMenu.Items(2)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/WhereToEatoth.aspx?Region=" & row("ID").ToString & "&Community=0&Category=0&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'Attractions

    parentItem = radMenu.Items(3)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/ThingsToDooth.aspx?Region=" & row("ID").ToString & "&Community=0&Category=0&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'Services

    parentItem = radMenu.Items(4)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/Servicesoth.aspx?Region=" & row("ID").ToString & "&Community=0&Category=0&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'Getting Here

    parentItem = radMenu.Items(5)

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/GettingHereoth.aspx?ProvID=" & Session("ProvID").ToString

    'Travel Tools

    parentItem = radMenu.Items(6)

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/TravelToolsoth.aspx?ProvID=" & Session("ProvID").ToString

    End If

    End Sub

    End

    Class






    Non Working Menu:

    Imports

    System.Data.Odbc

    Imports

    System.Data

    Imports

    Telerik.WebControls

    Partial

    Class controls_SideNav

    Inherits System.Web.UI.UserControl

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

    Dim dbcommand As OdbcCommand

    Dim dbconnection As OdbcConnection

    Dim dbreader As OdbcDataReader

    Dim sql As String

    dbconnection =

    New OdbcConnection("DSN=AtlanticPortal;")

    dbconnection.Open()

    sql =

    "Select * FROM Region WHERE ProvID = " & Session("ProvId").ToString

    dbcommand =

    New OdbcCommand(sql, dbconnection)

    dbreader = dbcommand.ExecuteReader(CommandBehavior.CloseConnection)

    Dim dt As DataTable = New DataTable

    dt.Load(dbreader)

    dbconnection.Close()

    dbreader.Close()

    Dim radMenu As RadMenu

    radMenu =

    CType(Me.FindControl("RadMenuSideNav"), Telerik.WebControls.RadMenu)

    'Home

    Dim parentItem As RadMenuItem

    Dim childItem As RadMenuItem

    parentItem = radMenu.Items(0)

    Select Case Session("ProvID").ToString

    Case "1"

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/NL.aspx"

    Case "2"

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/NS.aspx"

    Case "3"

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/NB.aspx"

    Case "4"

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/PEI.aspx"

    End Select

     

    If dt.Rows.Count > 0 Then

    'Hotels

    parentItem = radMenu.Items(2)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/WhereToStay.aspx?Region=" & row("ID").ToString & "&Community=0&Category=1&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'B&B's

    parentItem = radMenu.Items(3)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/WhereToStay.aspx?Region=" & row("ID").ToString & "&Community=0&Category=6&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'Cabins

    parentItem = radMenu.Items(4)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/WhereToStay.aspx?Region=" & row("ID").ToString & "&Community=0&Category=4&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'Campgrounds

    parentItem = radMenu.Items(5)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/WhereToStay.aspx?Region=" & row("ID").ToString & "&Community=0&Category=100&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'Restaurants

    parentItem = radMenu.Items(6)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/WhereToEat.aspx?Region=" & row("ID").ToString & "&Community=0&Category=3&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'attractions

    parentItem = radMenu.Items(7)

    For Each row As DataRow In dt.Rows

    childItem =

    New RadMenuItem

    childItem.Text = row(

    "Name").ToString

    childItem.NavigateUrl =

    "~/AtlanticPortal/en/ThingsToDo.aspx?Region=" & row("ID").ToString & "&Community=0&Category=0&CategoryName=Attraction&ProvID=" & Session("ProvID").ToString & "&RegionName=" & row("Name").ToString

    parentItem.Items.Add(childItem)

    Next

    'Getting Here

    parentItem = radMenu.Items(8)

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/GettingHere.aspx?ProvID=" & Session("ProvID").ToString

    'Travel Tools

    parentItem = radMenu.Items(9)

    parentItem.NavigateUrl =

    "~/AtlanticPortal/en/TravelTools.aspx?ProvID=" & Session("ProvID").ToString

    End If

    End Sub

    Protected Sub RadMenuSideNav_ItemClick(ByVal sender As Object, ByVal e As Telerik.WebControls.RadMenuEventArgs) Handles RadMenuSideNav.ItemClick

    End Sub

    End

    Class




  7. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 Aug 2008 Link to this post

    Hello grant,

    Have you managed to fix this?

    I do not see the __doPostBack in the source of the second page.

    Greetings,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top