Please enable Javascript to correctly display the contents on Dot Net Tricks!

Disable cut, copy and paste in textbox using jquery, javascript

  Author : Shailendra Chauhan
Updated On : 19 Jul 2012
Total Views : 24,949   
 

Due to some reasons (like don’t allow to copy Email from Email TextBox to Confirm Email TextBox), we restrict users to copy, paste and cut contents from TextBox by using CTRL+C, CTRL+V and CTRL+X. We can implement this functionality by using below methods.

Disable cut, copy & paste using Javascript

  1. When we don't want to display any message on cut, copy & paste

     <asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"></asp:TextBox> 

  2. When we want to display an alert message on copy, paste and cut

     <script language="javascript" type="text/javascript">
    function DisableCopyPaste (e) 
    {
     // Message to display
     var message = "Cntrl key/ Right Click Option disabled";
     // check mouse right click or Ctrl key press
    var kCode = event.keyCode || e.charCode; 
    //FF and Safari use e.charCode, while IE use e.keyCode
     if (kCode == 17 || kCode == 2)
     {
     alert(message);
     return false;
     }
    }
    </script>
     <asp:TextBox ID="TextBox1" runat="server" onKeyDown="return DisableCopyPaste(event)"onMouseDown="return DisableCopyPaste (event)"></asp:TextBox> 

Disable cut, copy & paste using JQuery

 <script type="text/javascript">
$(document).ready(function() {
 $('#TextBox1').bind('copy paste cut',function(e) { 
 e.preventDefault(); //disable cut,copy,paste
 alert('cut,copy & paste options are disabled !!');
 });
});
</script>
 <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox> 
YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
14 DEC
ASP.NET MVC with AngularJS Development (online)

MON-FRI 07:30 AM- 09:00 AM IST

Know More
5 DEC
AngularJS Development (online)

Mon - Fri     6:30 AM-7:30 AM IST

3 DEC
AngularJS Development (offline)

SAT,SUN     11:00 AM-12:30 PM IST

3 DEC
MEAN Stack Development (offline)

Sat, Sun     (09:30 AM-11:00 AM IST)

26 NOV
ASP.NET MVC with AngularJS Development (offline)

(SAT,SUN)     03:30 PM-05:00 PM IST

24 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     09:30 PM-11:00 PM IST

12 NOV
ASP.NET MVC with AngularJS Development (offline)

SAT,SUN     08:00 AM-09:30 AM

3 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     07:30 AM-09:00 AM IST

25 OCT
.NET Development (offline)

Mon-Fri     9:00 AM-11:00 AM IST

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+