How to disable right click in asp.net, C# using javascript


Add this attribute to the BODY Tag to disable the right click menu everywhere on the page.

<body oncontextmenu=”return false;”>

If you want disable dragging of images and text selection, add this attribute to the BODY Tag.

<body ondragstart =”return false;”>

Below this script is to disable right click menu and dragging of images and text selection for all browsers.

<script type=”text/javascript”>
function md(e) {
try { if (event.button == 2 || event.button == 3) return false; }
catch (e) { if (e.which == 3) return false; }
}
document.oncontextmenu = function () { return false; }
document.ondragstart = function () { return false; }
document.onmousedown = md;
</script>