Home > Csharp, DotNet, Javascript, JQuery > Disable right click on a web page in asp.net/C# using Jquery/Javascript

Disable right click on a web page in asp.net/C# using Jquery/Javascript

How to disable right click functionality from the asp.net web page

In some of the web page has the requirement to protect source code from the users. Users can right click the page and take the source code. In order protect right click functionality on the web page we can implement javascript functionality to prevent user’s right click on the web page. So user not able to access features available on the right click menus.

By implementing javascript method we can identify the right click event from the user by checking the button code and prevent if the user clicks right click. Below mentioned web page prevented to click right click by the user. When the user trying to right click it will return warning message to user and return the action.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DisableRightClick.aspx.cs"
 Inherits="ExperimentLab.DisableRightClick" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
 <title>Sample to Disable Right Click of Page</title>
 <script language="JavaScript" type="text/javascript">
 //Message to display whenever right click on website
 var message = "Sorry, Right Click have been disabled.";
 function click(e) {
 if (document.all) {
 if (event.button == 2 || event.button == 3) {
 return false;
else {
 if (e.button == 2 || e.button == 3) {
 return false;
if (document.all) {
 document.onmousedown = click;
else {
 document.onclick = click;
 <form id="form1" runat="server">
 In this page right click not allowed.
    December 4, 2012 at 4:51 pm

    This is not useful . for me. I am developing a project and I m unable to hide the source code! contact me on rahul12augt@gmail.com

  2. March 28, 2014 at 9:01 pm

    It acts immediately on all your garage concerns as quickly as possible.
    This article will take you through the steps to safely remove the hinge and roller assembly and replace the roller.
    He loves his house and can’t stop talking about
    the great people, the bustling library, and wonderful food that visitors can find in the area.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: