Here is the script that disables right mouse button click in an ASP.NET page. You can put this script in your head tag.
- <head id="Head1" runat="server">
- <title>Web Page</title>
- <script type="text/javascript">
- var message = "Function Disabled!";
- function clickIE4() {
- if (event.button == 2) {
- alert(message);
- return false;
- }
- }
- function clickNS4(e) {
- if (document.layers || document.getElementById && !document.all) {
- if (e.which == 2 || e.which == 3) {
- alert(message);
- return false;
- }
- }
- }
- if (document.layers) {
- document.captureEvents(Event.MOUSEDOWN);
- document.onmousedown = clickNS4;
- }
- else if (document.all && !document.getElementById) {
- document.onmousedown = clickIE4;
- }
- document.oncontextmenu = new Function("return false")
- </script>
- </head>
When a user right mouse click on a page, he/she will get a message, Function Disabled!. You can change it to anything you like.
The key is to capture the mouse down click event and in the event handler, show the message box and not display the browser context menu.