Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

Disable Right click on Web Page and images in ASP.NET

Article:
Viewed:  1210 
Posted On:  19/02/2014 07:01:55 
How we can disable Right Click on any aspx page or any image in asp.net ? 

 

In this article I am going to show how we can disable right click on our web form or images in asp.net.


 To disable Right Click on an image:

    <asp:Image ID="MyImage1" runat="server" ImageUrl="Image/1.png"  oncontextmenu="return false;" />

    <img alt="MyImage2" src="Image/2.png" oncontextmenu="return false;"/>

To Disable Right Click on ASPX page:

<body oncontextmenu="return false;">
    <form id="form1" runat="server">
    <div>
        <img alt="MyImage" src="2.jpg" />
    </div>
    </form>
</body>
 

 
If You want to show some error or warning message the use the below code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Make Right Click Disabled</title>
    <script type="text/javascript">
        function MakeDisableRightClick() {
            alert("Hi.. Right Click is not permitted...");
            return false;
        }
    </script>
 </head>
<body oncontextmenu=" return MakeDisableRightClick();">
    <form id="form1" runat="server">
    <div>
        <img alt="MyImage" src="2.jpg" />
    </div>
    </form>
</body>
</html>

When Run the Programme:

Disable Right Click.png

Image 1.

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us