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
- 292,071 hits
Top Posts
Recent Posts
- How to access all types of server controls in ASP.Net using Javscript/JQuery OR Clear all server controls values using javascript or Jquery
- How to implement Cache mechanism in ASP.Net/C# using simple example OR What is Output Caching and Fragment Caching in ASP.Net/C#
- 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.
Archives
- June 2013 (1)
- May 2013 (2)
- 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
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.