1

I'm binding some items to a menu. Assuming, my site address is "www.abc.com/Dev", the menu items automatically get the navigateUrl of "www.abc.com/Dev/#".

Now, these menu items when clicked open some applications like 'Notepad'.

Because of the navigateUrl property of these menu items, if I right click on the items, it gives me a context menu and if I click on 'Open in New Window', it takes me back to my original site.

Ideally, this is the wrong behaviour. Is there some way I can prevent the setting of the navigateUrl? I tried making:

menuItem.NavigateUrl = null

But once the menuItems are initialized, they have the navigateUrl property set with #.

Is there any way I can prevent this.

Torpedo
  • 129
  • 4
  • 14

2 Answers2

2
menuItem.NavigateUrl = "javascript: void(0);";
Akhil
  • 7,570
  • 1
  • 24
  • 23
  • This prevents the navigation from happening. But unfortunately, it disables the default left click behaviour. The menu item does nothing once it is clicked. :( – Torpedo Jul 16 '12 at 08:36
1

Well do the following in that case,

put menuItem.NavigateUrl = string.Empty or menuItem.NavigateUrl = "" which will produce "#"

On the top of that add menuItem.attributes.add("onclick","TrackRightClickAndReturnFalse")

This way you can have "#" but you can prevent the right click button click on it...

See this How to disable right-click context-menu in javascript to see how you can get idea on how to disable right click.

I hope you understand my concept.

Community
  • 1
  • 1
Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45
  • Thanks Jigar Pandya, I tried this: menuItem.Attributes.Add("onContextMenu","return false;"); This essentially prevents the context menu from appearing. Thanks once again. :) – Torpedo Jul 16 '12 at 09:54
  • I would love to do that. But I'm relatively new to Stack Overflow and I dont have enough reputation points to do that. :( – Torpedo Jul 16 '12 at 10:22