When requesting sensitive information from the end user such as passwords, credit card details, and transaction pin numbers used in Internet banking, etc. it is preferred that the web user keys in the characters manually rather than pasting from the clipboard.
In previous post of jquery we see how can we validate complete website with a single code of jquery and how can we delay execution of methods with java script
You can disable cut, copy and paste by simply writing a small piece of code by jQuery.
Step 1. Add a text box in on your page.
<asp:TextBoxID="txtTest"runat="server">asp:TextBox>
Step 2. Add jQuery file on the header. (I am using jQuery 1.4 for this sample)
Step 3. Paste below code on your page.
<scripttype="text/javascript"> $(document).ready(function(){ $('#<%=txtTest.ClientID%>').bind('cut copy paste',function(e){ e.preventDefault(); alert("Cut/Copy/Paste disabled in this textbox"); }); }); script>
Explanation of code :
1. In the document.ready() function in the jQuery script block, use bind to attach the required event handler for cut, copy, and paste events for the New Password TextBox:
$('#<%=txtTest.ClientID%>').bind('cut copy paste',function(e){
2. Override the default cut/copy/paste behavior:
e.preventDefault();
3. Display an information message:
alert("Cut/Copy/Paste disabled in this textbox");