Context Menu in an asp:Content... I got an error on right-click

Jul 20, 2007 at 3:37 PM
Hi all,

I have an page with a xGrid and a context menu. All this controls are set in an asp:Content.

When I right-click on a row from my grid, I got this error :
Microsoft JScript runtime error: 'ContextMenuCustomer_Root' is undefined

on this line :
oncontextmenu="return _showContextMenu(ContextMenuCustomerRoot, 2);"

Anyone have a idea?
Jul 20, 2007 at 6:06 PM
Ok sorry, I got the latest version and my problem vs master-page is solved.

I found another bug... when the grid height is bigger than the page size, first we got a scrollbar and that ok, but if I scroll-down to the end the page to see the last line of my grid and I right-click on it, the context menu appear but at the top of the page. When you right-click (from bottom) you think the context menu don't appear, but in fact he appear but you need to scroll-up to see it.
Aug 15, 2007 at 9:16 PM
I had the same issue where if I scrolled down, the Context Menu would be way off. I did the followings which fixed it but so far with one problem, it looks for a table with id XGrid. so, when you declare your XGrid, you have to id it XGrid as well.

Here is the code: in file: ContextMenuJS.js

function __showContextMenu(menu, rowID)
{
var menuOffset = 2

var varRowHeight = document.getElementById("XGrid").clientHeight / document.getElementById("XGrid").rows.length;

var rowID = document.getElementById('_ROWID');
if (_rowID != null)
_rowID.value = rowID;


var tableRow = _rowID;

menu.style.left = window.event.x - menuOffset;
menu.style.top = menuOffset + topOffset + _rowID.value * varRowHeight;

menu.style.display = "";
window.event.cancelBubble = true;

return false;
}
Oct 23, 2007 at 11:02 PM
I found that replacing the __showContextMenu method in the CustomControls project with the following code solves the problem (haven't tested it with anything else than IE7 though), such that the menu is shown correctly independently of the id of the XGrid thereby enabling having more than one XGrid on a page.

function __showContextMenu(menu, rowID)
{
var menuOffset = 2;

menu.style.left = mouseX(window.event) - menuOffset;
menu.style.top = mouseY(window.event) - menuOffset;
menu.style.display = "";

var rowID = document.getElementById('_ROWID');
if (_rowID != null)
_rowID.value = rowID;

window.event.cancelBubble = true;

return false;
}
function mouseX(evt)
{
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
return evt.clientX + (document.documentElement.scrollLeft ?
document.documentElement.scrollLeft :
document.body.scrollLeft);
else return null;
}
function mouseY(evt)
{
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
return evt.clientY + (document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body.scrollTop);
else return null;
}