I am using WebMenu as a contextmenu for ultrawebgrid cells. The contextmenu works fine if I place the webgrid and webmenu directly in the page. The problem starts when I am trying to create a usercontrol using webgrid and webmenu, contextmenuclick(right click on grid cell) gives me an error saying "Popup name not valid".
igmenu_showMenu("<%=this.MROContextMenu.ClientID %>",null,0,0);
Thanks
Hello,
You can use the client-side InitializeMenu event of UltraWebMenu to find out the ID of the menu, and later use it to show the context menu. I did a quick search in our forum archives and found out that a customer has reported a problem very similar to yours (same error message while trying to show context menu for grid or treeview) and as the discussion goes on, it appears that the InitializeMenu approach resolved the problem.
Link (I am using tinyurl since the link is very long and gets corrupted in the HTML editor Community Server is using):
http://tinyurl.com/yu2qjd
I hope this helps. Please, let me know if this is not working / not applicable in your setup.
Thank you very much for that pointer. I have tried using the InitializeMenu event and got the menu id. Now that error has gone but I am not able to see the menu. No error and no context menu. Strange thing!!! any ideas??
The code now is :
<MenuClientSideEvents ItemClick="ContextMenuItemClick" InitializeMenu="InitializeLayout" />
In BLOCKED SCRIPT
{
MyMenuId = menuId;
alert(MyMenuId);
}
igmenu_showMenu(MyMenuId,null,0,0);
Thanks.
Thanks for the follow-up. Is the alert showing the correct client-side ID?
In any case, I believe the key here could be the parameters to the igmenu_showMenu method. I've found out several test project demonstrating this live in action, and they always required a valid "event" (the second parameter), plus some coordinates - x,y (third and fourth parameters).
You can find the following KB article useful:
HOWTO:How to show and hide the UltraWebMenu when used as a context menu
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=10083
It demonstrates sample code/approach, plus there a couple of projects attached to it where you can see this live in action.
Its rendering the menuid as "MROGridControlMROContextMenu" i.e., parentcontrolid+contextmenuid.
I have avoided the event parameter as I have read that event is understood only by IE not other browsers and I am targeting IE and Firefox browsers.
To be sure if event param is causing the problem, I have tested the code passing the event parameter but it still didnot work. Not sure why !!
Take a look at the Excel Copy & Paste sample in the samples browser. I spent a good day banging my head against the wall trying to figure out how to get a context menu positioned correctly cross browser, so I definitely feel your pain. As much as I understand why firefox doesn't have a global "event" object, it sure makes things hard :) The key is to pass the "event" parameter into the function as a parmeter. Firefox will always use the first parameter in an event handler as the event object.
Then you can calculate the position using the event object. A warning though - calculating positions cross browser is another headache. Lastly, you want to be sure to call igmenu_showMenu as you're doing above (menuid, null, x,y). I remember running into an issue with quotations not being correctly placed around my ID under some odd configuration, so you'll want to do a quick views source on your HTML page to be sure that <%= ...%> is actually rendering out what you think it should.
hth,
-Tony
Thanks for your time and suggestions. I have gone through the Excel Copy paste sample before and infact that sample is the base for my grid.
I had a work around for my problem of contextmenu. I was struggling to create a usercontrol consisting webgrid and webmenu and it didnot work because of problem with MenuID. So I seperated them out. I have put the webgrid in the usercontrol and webmenu in the aspx page and ran the same scripts and it worked.
Now the only issue which remains is what you have mentioned "positioning the contextmenu". If I pass 0,0 as x,y then the menu is showing fine for some inner column cells but going out of screen for cells which are in the last column. Can I have the codebit of what you are talking abt passing event object, calculating the position so that it will work for firefox also?
I would actually recommend that rather than coding up the event handler explicitly as was done in the sample, you can use ASP.NET AJAX extensions to add the handler. The eventargs that you will get for your handler will take care of abstracting away differences, and you can use screenX and screenY to position your menu. http://asp.net/AJAX/Documentation/Live/ClientReference/Sys.UI/DomEventClass/SysUIDomEventAddHandlerMethod.aspx
If you are already using ASP.NET 3.5, you can try using the not very popular, but very helpful client-side method getLocation to get the coordinates of the element clicked and place the menu there. Some information can be found here:
http://weblogs.asp.net/bleroy/archive/2008/01/29/getting-absolute-coordinates-from-a-dom-element.aspx
If you are still using ASP.NET 1.x / 2.x, you can try using the FindPos function proposed by the QuirksMode website (a very useful site on all things Javascript/DOM)
http://www.quirksmode.org/js/findpos.html
Hope this helps / provides additional clues.
I can't say for sure. Browsers stink when it comes to this aspect. They all give different values depending on the elements, containers, positioning, and especially whether IE is in QuirksMode or standards mode. The only way to be sure is to test the scenarios in your environment. It's actually pretty easy to write a piece that will work well for a speific scenario - the difficulty is writing a generic solution that will work in all scenarios (a div inside of a table inside of a div, absolutely positioned, floated left, etc...)
Hey Tony,
I was skimming through the KnowledgeBase for some stuff on formulas and found this article on finding the x,y positions of cell.
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=4065
Does cell.offsetLeft and cell.offsetTop work on all browsers?
Sairam