Database value true contextmenu

14 posts, 0 answers
  1. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 16 Dec 2009 Link to this post

    Have a problem with the context menu on the radmenucontrol
    The contextmenu works fine but here is the scenario

    MENU ITEM 1         MENU ITEM 2              MENU ITEM 3
                                       - SUBMENU ITEM 2-1        -SUBMENU ITEM 3-1
                                                                                                 - SUBMENU ITEM 3-2

    Ok, the context menu will work on the lowerst item in the tree
    In this case it will work on
    - MENU ITEM 1
    - SUBMENU ITEM 2-1
    - SUBMENU ITEM 3-2

    But all other items the context menu is disabled for some reason.

    Here is the code.
    ASPX :
    <telerik:RadContextMenu ID="RadContextTopMenu" runat="server" OnClientShowing="topmenuShowing" OnItemClick="RadTopMenu1_ItemClick" Skin="Windows7">  
       <Items> 
           <telerik:RadMenuItem runat="server" Text="Menupagina toevoegen">  
           </telerik:RadMenuItem> 
           <telerik:RadMenuItem runat="server" Text="SubPagina Toevoegen">  
           </telerik:RadMenuItem> 
           <telerik:RadMenuItem runat="server" Text="Pagina Wijzigen">  
           </telerik:RadMenuItem> 
           <telerik:RadMenuItem runat="server" Text="Pagina Verwijderen">  
           </telerik:RadMenuItem> 
       </Items> 
       <Targets> 
           <telerik:ContextMenuControlTarget ControlID="RadTopMenu1" /> 
       </Targets> 
    </telerik:RadContextMenu>   
     
    <telerik:RadScriptBlock runat="server" ID="RadScriptBlock2">  
     
        <script type="text/javascript">  
            function topmenuShowing(sender, args) {  
                var target = args.get_targetElement();  
                if (target.className != "rmText") {  
                    args.set_cancel(true);  
                }  
                else {  
                    var panelBarItem = $find("<%=RadTopMenu1.ClientID %>").findItemByText(target.innerHTML);  
                    sender.trackChanges();  
                    sender.get_items().getItem(0).get_attributes().setAttribute("mItem", panelBarItem.get_attributes().getAttribute("PageID"));  
                    sender.commitChanges();  
                }  
                sender.hide();  
            }  
       
        </script> 
     
    </telerik:RadScriptBlock> 
     <telerik:RadWindowManager ID="topMenuradwindow" EnableViewState="false" runat="server" Skin="Windows7">  
    </telerik:RadWindowManager>      
     
    <telerik:RadMenu ID="RadTopMenu1" runat="server" OnItemClick="Click" Style="z-index: 2;" /> 
      

    VB, just for info but this works
    Protected Sub RadTopMenu1_ItemClick(ByVal sender As ObjectByVal e As RadMenuEventArgs)  
           Private Sub BindToDataSet()  
     
            Dim adapter As New SqlDataAdapter("SELECT * FROM TblPages where MenuID = " + MenuIDvalue, _  
                ConfigurationManager.ConnectionStrings("Varodb").ConnectionString)  
     
            Dim Menu As New DataSet()  
     
            adapter.Fill(Menu)  
            RadTopMenu1.DataTextField = "Pagename" 
            RadTopMenu1.DataFieldID = "ID" 
            RadTopMenu1.DataFieldParentID = "PageID" 
     
            RadTopMenu1.DataSource = Menu  
            RadTopMenu1.DataBind()  
        End Sub 
     
     Protected Sub RadMenu1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadTopMenu1.ItemDataBound  
            Dim dataRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)  
            e.Item.Attributes("PageID") = dataRow("ID").ToString()  
        End Sub 
     
            Dim MenuitemValue As String = RadContextTopMenu.Items(0).Attributes("mItem").ToString()  
     
            Select Case e.Item.Text  
                Case "Menupagina toevoegen" 
     
                  'some code  
                Case "SubPagina Toevoegen" 
     
                    'some code  
                    Exit Select 
     
                Case "Pagina Wijzigen" 
     
                   'some code  
     
                    Exit Select 
     
     
                Case "Pagina Verwijderen" 
     
                    'some code  
                    Exit Select 
     
            End Select 
     
     
        End Sub 


    But i think there is something wrong with this line :

    sender.get_items().getItem(0).get_attributes().setAttribute(

    "mItem", panelBarItem.get_attributes().getAttribute("PageID"));

    Anyone has an idea ?

     

  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 21 Dec 2009 Link to this post

    Hi David,

    This behavior is expected since you have the following check:

    if (target.className != "rmText") { 
      args.set_cancel(true); 

    Items with no children will have class="rmText", but items with children will have class="rmText rmExpandDown", so you cancel the OnClientShowing event for the those cases.

    I suggest you use the match() javascript method to check if a string contains a substring.


    Greetings,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 22 Dec 2009 Link to this post

    do you have an example of that somewhere ?
  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 24 Dec 2009 Link to this post

    Hi David,

    Please, try the following modification and let us know if it helps:

    if (target.className != target.className.match("rmText")) {  
      args.set_cancel(true);  
    }


    Best wishes,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 04 Jan 2010 Link to this post

    Hi,

    I tried to change it, but it still the same problem.

    Current code :
    <script type="text/javascript">  
            function topmenuShowing(sender, args) {  
                var target = args.get_targetElement();  
                if (target.className != target.className.match("rmText")) {  
                    args.set_cancel(true);  
                }  
                else {  
                    var panelBarItem = $find("<%=RadTopMenu1.ClientID %>").findItemByText(target.innerHTML);  
                    sender.trackChanges();  
                    sender.get_items().getItem(0).get_attributes().setAttribute("mItem", panelBarItem.get_attributes().getAttribute("PageID"));  
                    sender.commitChanges();  
                }  
                sender.hide();  
            }  
       
        </script> 
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 06 Jan 2010 Link to this post

    Hello David Blok,

    Can you please explain why do you need that check in your code? What is the goal?

    Greetings,
    Veskoni
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 11 Jan 2010 Link to this post

    Well its regarding my original post.

    Because without the check it always takes the last sub menu of that node.
    So the context menu wont work if there is a submenu active, it will only work on the submenu.

    Original post :
    MENU ITEM 1         MENU ITEM 2              MENU ITEM 3
                                       - SUBMENU ITEM 2-1        -SUBMENU ITEM 3-1
                                                                                                 - SUBMENU ITEM 3-2

    Ok, the context menu will work on the lowerst item in the tree
    In this case it will work on
    - MENU ITEM 1
    - SUBMENU ITEM 2-1
    - SUBMENU ITEM 3-2
  8. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 12 Jan 2010 Link to this post

    Hi David Blok,

    I could not reproduce the original problem. Please find attached my test page and let me know how to reproduce it.

    Thanks.

    Kind regards,
    Veskoni
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 13 Jan 2010 Link to this post

    Hi,

    The code your wrote works perfect but thats not the problem.

    the problem here is with the onclientshowing event : topmenushowing

    Contextmenu code:
    <telerik:RadContextMenu ID="RadContextTopMenu" runat="server" OnClientShowing="topmenuShowing" OnItemClick="RadTopMenu1_ItemClick" Skin="Windows7">  
       <Targets>  
           <telerik:ContextMenuControlTarget ControlID="RadTopMenu1" />  
      </Targets>  
    </telerik:RadContextMenu>   
     

    function topmenushowing :
    <telerik:RadScriptBlock runat="server" ID="RadScriptBlock2">  
     
        <script type="text/javascript">  
            function topmenuShowing(sender, args) {  
                var target = args.get_targetElement();  
                if (target.className != target.className.match("rmText")) {  
                    args.set_cancel(true);  
                }  
                else {  
                    var panelBarItem = $find("<%=RadTopMenu1.ClientID %>").findItemByText(target.innerHTML);  
                    sender.trackChanges();  
                    sender.get_items().getItem(0).get_attributes().setAttribute("mItem", panelBarItem.get_attributes().getAttribute("PageID"));  
                    sender.commitChanges();  
                }  
                sender.hide();  
            }  
       
        </script>  
     
    </telerik:RadScriptBlock> 

    To get the database value from a menu item.
    Database value code
        Protected Sub RadTopMenu1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadTopMenu1.ItemDataBound  
            Dim dataRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)  
            e.Item.Attributes("PageID") = dataRow("ID").ToString()  
        End Sub 

  10. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 18 Jan 2010 Link to this post

    Hi David Blok,

    I am afraid I still do not understand what is the problem. Can you please elaborate a bit more?


    All the best,
    Veskoni
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 18 Jan 2010 Link to this post

    Well i don't know what i have to say more.

    link this to your code :
    <telerik:RadScriptBlock runat="server" ID="RadScriptBlock2">     
        
        <script type="text/javascript">     
            function topmenuShowing(sender, args) {     
                var target = args.get_targetElement();     
                if (target.className != target.className.match("rmText")) {     
                    args.set_cancel(true);     
                }     
                else {     
                    var panelBarItem = $find("<%=RadTopMenu1.ClientID %>").findItemByText(target.innerHTML);     
                    sender.trackChanges();     
                    sender.get_items().getItem(0).get_attributes().setAttribute("mItem", panelBarItem.get_attributes().getAttribute("PageID"));     
                    sender.commitChanges();     
                }     
                sender.hide();     
            }     
          
        </script>     
        
    </telerik:RadScriptBlock>    
     

    and use OnClientShowing="topmenuShowing" on RadContextMenu.

    The context menu will only work on : last node of the tree.
    MENU ITEM 1         MENU ITEM 2              MENU ITEM 3
                                       - SUBMENU ITEM 2-1        -SUBMENU ITEM 3-1
                                                                                                 - SUBMENU ITEM 3-2

    Ok, the context menu will work on the lowerst item in the tree
    In this case it will work on
    - MENU ITEM 1
    - SUBMENU ITEM 2-1
    - SUBMENU ITEM 3-2


  12. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 20 Jan 2010 Link to this post

    Hi David Blok,

    I added the provided javascript code to the page I sent you but could not reproduce the problem.
    The ItemClick server event fires for every context menu item click.
    What is different in your case?

    Please find attached the modified page.

    Kind regards,
    Veskoni
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  13. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 26 Jan 2010 Link to this post

    Hi,

    The difference in my case is :

       Protected Sub RadTopMenu1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadTopMenu1.ItemDataBound     
            Dim dataRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)     
            e.Item.Attributes("PageID") = dataRow("ID").ToString()     
        End Sub    
     

    I have an attribute PageID linked to every menu item.
    That page ID gets transfered with the the clientevent : topmenuShowing

    So on serverside i can request the PageID value of that menuitem with :
    Dim MenuitemValue As String = RadContextTopMenu.Items(0).Attributes("mItem").ToString() 

  14. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 28 Jan 2010 Link to this post

    Hi David Blok,

    I think the best way to proceed is to send us a sample working page via a support ticket.

    This will help us to find a working solution for you faster.

    All the best,
    Veskoni
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top