User-1753546938 posted
I have a custom control that takes a target control and adds an attribute (oncontextmenu) to the target control. I also have some javascript that I register to the parent page. The javascript I register contains the Client ID of a control
within the custom control. The problem is when I do a right click I get an error in the javascript function stating that the control is null even though the Client ID is correct and the rendered html contains the forementioned control with the same ID.
Here is the javascript I register:
StringBuilder menuSB = new StringBuilder("function displayMenu()")
.AppendLine("{")
.AppendLine("var menu = document.getElementById(" + MenuPnl.ClientID + ");")
.AppendLine("var mouseXPos = event.clientX + document.body.scrollLeft;")
.AppendLine("var mouseYPos = event.clientY + document.body.scrollTop;")
.AppendLine("menu.style.left = mouseXPos;").AppendLine("menu.style.top = mouseYPos;")
.AppendLine("menu.style.visibility = 'visible';").AppendLine("menu.focus();")
.AppendLine("return false;").AppendLine("}");
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "displayMenu", menuSB.ToString(), true);