In this step we will see the complete code for the .aspx page; let us see the code given below.
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="disableclick.aspx.cs" Inherits="disableclick" %>
<!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>
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" language="javascript">
$(function () {
$(this).bind("contextmenu", function (e) {
e.preventDefault();
});
});
</script
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>
Disable Right Click</h3>
Rohatash Kumar<br /><img alt="" src="Esplorer2.jpg" />
</div>
</form>
</body>
</html>
Now test the application with a right-click.
Step 2 : We have defined e.preventDefault() method in the step1. We just need to bind the contextmenu event with the document element and replace return false in place of e.preventDefault(). In the head section we copy the following code.
<script type='text/javascript'>
$(document).ready(function () {
$(document).bind("contextmenu", function (e) {
return false;
});
});
</script>
In this step we will see the complete code for the .aspx page let see the code given below.
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="disableclick.aspx.cs" Inherits="disableclick" %>
<!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>
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type='text/javascript'>
$(document).ready(function () {
$(document).bind("contextmenu", function (e) {
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>
Disable Right Click</h3>
Rohatash Kumar<br />
<img alt="" src="Esplorer2.jpg" />
</div>
</form>
</body>
</html>
The above code also disables right-click function, the same as shown in the step1.
Resources