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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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) {
alert(message);
return false;
}
}
else {
if (e.button == 2 || e.button == 3) {
e.preventDefault();
e.stopPropagation();
alert(message);
return false;
}
}
}
if (document.all) {
document.onmousedown = click;
}
else {
document.onclick = click;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
In this page right click not allowed.
</div>
</form>
</body>
</html>
Leave a Reply Cancel reply
Search other topic from here
Blog Stats
- 205,264 hits
Top Posts
- How to PIVOT table in SQL Server / PIVOT table example in SQL Server
- How to call serverside function from client side javascript in ASP.Net?
- How to UNPIVOT table in SQL Server / UNPIVOT table example in SQL Server
- How to Import CSV File Into SQL Server Using Bulk Insert in SQLServer?
- How to create a simple Ajax Collapsible Panel Extender in asp.net
- How to access URL or URL parts using javascript / Get the Website URL using JavaScript
- Nested Common Table Expression(CTE) in SQL Server 2005/2008
- How to implement BalloonPopupExtender in ASP.Net/C# OR Ballon Popup Extender Sample in ASP.Net/C#
- How to get all classes and methods from a dll in ASP.Net C# using Reflection
- Collapsible panel extender samples in ASP.Net indifferent scenario
- How to create breadcrumbs in ASP.Net/C# OR Show Navigations for each pages in ASP.Net/C# OR How to implement Sitemap in ASP.Net
- How to create a news scroller using HTML marquee.
Recent Posts
- How to implement CAPTCHA image validation in ASP.Net/C# OR CAPTCHA image validator Sample in ASP.Net/C#
- How to implement SQL Bulk Copy in SQL Server OR Bulk insert into SQL Server using SQL BulkCopy
- How to merge two data tables in ASP.Net/C# OR Merge 2 DataTables and store in a new one in ASP.Net/C#
- How to implement Password validation in ASP.Net/C# OR Implement Password strength using Jquery in ASP.Net
- How to create breadcrumbs in ASP.Net/C# OR Show Navigations for each pages in ASP.Net/C# OR How to implement Sitemap in ASP.Net
- How to create a drag able and resizable div in ASP.Net/C# OR How to make a div Dragable and Resizable using Jquery in ASP.Net/C#
- How to implement BalloonPopupExtender in ASP.Net/C# OR Ballon Popup Extender Sample in ASP.Net/C#
- How to create always visible div using Ajax/ Always visible div in ASP.Net using Ajax
- Example for All Types of SQL JOIN (Inner Join, Cross Join, Outer Join, Self Join)
- How to Create a Data Table Dynamically with sample data and Bind to Grid/Create datatable with sample data.
- How to delete large amount of rows from table in SQL
- How to Create and use Table-Valued Parameter in C# and T-SQL/ How to pass table to stored procedures in SQL
Archives
- May 2013 (1)
- October 2012 (4)
- September 2012 (6)
- July 2012 (4)
- June 2012 (1)
- May 2012 (1)
- March 2012 (2)
- February 2012 (2)
- January 2012 (1)
- October 2011 (2)
- September 2011 (5)
- August 2011 (1)
- July 2011 (6)
- June 2011 (18)
- May 2011 (14)
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