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

[Solved] Database value true contextmenu

13 Answers 149 Views
Menu
This is a migrated thread and some comments may be shown as answers.
David Blok
Top achievements
Rank 1
David Blok asked on 16 Dec 2009, 07:45 AM
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 ?

 

13 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 21 Dec 2009, 09:12 AM
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.
0
David Blok
Top achievements
Rank 1
answered on 22 Dec 2009, 08:33 AM
do you have an example of that somewhere ?
0
Peter
Telerik team
answered on 24 Dec 2009, 04:39 PM
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.
0
David Blok
Top achievements
Rank 1
answered on 04 Jan 2010, 09:35 AM
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> 
0
Veselin Vasilev
Telerik team
answered on 06 Jan 2010, 04:25 PM
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.
0
David Blok
Top achievements
Rank 1
answered on 11 Jan 2010, 07:43 AM
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
0
Veselin Vasilev
Telerik team
answered on 12 Jan 2010, 02:35 PM
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.
0
David Blok
Top achievements
Rank 1
answered on 13 Jan 2010, 12:32 PM
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 

0
Veselin Vasilev
Telerik team
answered on 18 Jan 2010, 11:11 AM
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.
0
David Blok
Top achievements
Rank 1
answered on 18 Jan 2010, 01:59 PM
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


0
Veselin Vasilev
Telerik team
answered on 20 Jan 2010, 03:20 PM
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.
0
David Blok
Top achievements
Rank 1
answered on 26 Jan 2010, 12:19 PM
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() 

0
Veselin Vasilev
Telerik team
answered on 28 Jan 2010, 01:24 PM
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.
Tags
Menu
Asked by
David Blok
Top achievements
Rank 1
Answers by
Peter
Telerik team
David Blok
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or