Disable Right Click In ASP.NET

Here is code snippet shows how to disable right mouse button click in an ASP.NET page.

Here is the script that disables right mouse button click in an ASP.NET page. You can put this script in your head tag.  
  1. <head id="Head1" runat="server">  
  2. <title>Web Page</title>  
  3. <script type="text/javascript">  
  4. var message = "Function Disabled!";  
  5. function clickIE4() {  
  6. if (event.button == 2) {  
  7. alert(message);  
  8. return false;  
  9. }  
  10. }  
  11. function clickNS4(e) {  
  12. if (document.layers || document.getElementById && !document.all) {  
  13. if (e.which == 2 || e.which == 3) {  
  14. alert(message);  
  15. return false;  
  16. }  
  17. }  
  18. }  
  19. if (document.layers) {  
  20. document.captureEvents(Event.MOUSEDOWN);  
  21. document.onmousedown = clickNS4;  
  22. }  
  23. else if (document.all && !document.getElementById) {  
  24. document.onmousedown = clickIE4;  
  25. }  
  26. document.oncontextmenu = new Function("return false")  
  27. </script>  
  28. </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.