|
Rank: Member Groups: Member
Joined: 7/17/2009 Posts: 17
|
I know this issue has been discussed in other threads and I have tried all the suggestions I have found without any luck.
I have a Grid, and I have a Contextmenu attached to that Grid. Plain and 'simple'.
When I right-click on the Grid I get my Contextmenu and when I select a choice in the menu I get the server side event that I expect.
BUT, the Grid.ContextItem and Grid.ContextCell are both null, so I haven't a clue where the Grid was clicked.
Are there any specific requirements for the ContextItem to be correctly assigned?
The Grid has FullRowMode=True. I have no client side scripts.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Gunnar wrote:I have no client side scripts. That is definitely wrong then. :) You will need client side scripts to show context menu for the Grid. Please see here for a working example of how to use context menu with Grid: http://demo.essentialobjects.com/Default.aspx?path=Grid\_i1\_i22Thanks!
|
|
Rank: Member Groups: Member
Joined: 7/17/2009 Posts: 17
|
Quote:You will need client side scripts to show context menu for the Grid I don't get it. I do not have any client scripts, yet the Contextmenu is displayed, I can use it and I get a server side event when I click a Contextmenu item that raises server events. So, everything works as expected except for the fact that when I get the Contextmenu item event on the server side, Grid.ContextItem and Grid.ContextCell are both null. I have no need for a client side script, and I cannot see anything in the client code you refer to that would change the fact that Grid.ContextItem and Grid.ContextCell are both null when I get the server side event. Or it it something in the script code that I miss?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You do not need client side JavaScript to just show the context menu. But you must use JavaScript to handle the Grid's ClientSideOnContextMenu event to display the context menu so that Grid can correctly record ContextItem and ContextCell. Otherwise it will be exactly what you saw: you will get the context menu but not ContextItem and ContextCell.
Thanks
|
|
Rank: Member Groups: Member
Joined: 7/17/2009 Posts: 17
|
OK thanks, I finally got it to work now. This is excellent functionality, but you really need to describe it better. When I re-read the description of the Grid.ContextItem Property I still can't see any requirements for the client side script to be present. Quote: When you use ClientSideOnContextMenu....it is often desired to know which item... Yes, it is probably often desired when using ClientSideOnContextMenu, and most probably when not using ClientSideOnContextMenu also... My suggestion is that you complement the documentation with a clear requirement that the ClientSideOnContextMenu must be used in order for the ContextItem to be present on the server side. Also, the example code on the page you referred to is somewhat confusing:
Code: JavaScript
//Show the context menu
var menu = eo_GetObject("<%=Menu1.ClientID%>");
eo_ShowContextMenu(e, "<%=Menu1.ClientID%>");
Besides the fact that I never got this piece of code to find anything (using my control name of course), I can't understand the creation of the menu variable that is never used... I got this to work though:
Code: JavaScript
//Show the context menu
var menu = eo_GetObject("Menu1");
eo_ShowContextMenu(e, menu.getId());
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Thank you very much for the feedback. It certainly makes perfect sense to clearly state that you must use ClientSideOnContextMenu in order for ContextItem and ContextCell to work.
The eo_GetObject in the sample is not necessary. It was there so that you can use it to modify the menu, which is often needed if you wish to modify the menu item text to reflect the current selected item cell (For example, change "Save" to "Save 'item A'", where 'Item A' is the selected cell content). Nevertheless, I agree with you that the code should comment it clearly.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 7/17/2009 Posts: 17
|
I've found another mystery with the contextmenu on the grid. With all the client side and server side code in place, everything works as expected for all grid rows except the first one.
In the client side function I can see the "g_itemIndex = item.getIndex();" register the correct row index: 0 for first row, 1 for second row and so on.
On the server side, I get a correct Grid.ContextItem object for rows 1 and above. When the first row is right clicked, I get null in Grid.ContextItem.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
This looks like a bug. We will look into it and see what we can find.
Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
We looked into the issue but have not been able to reproduce it. Can you provide a test page that can reproduce the problem?
Thanks!
|
|