Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Disable Cut Copy Paste Options in Textbox

Apr 21, 2013
Introduction

Here I will explain how to disable cut, copy and paste functionality for the Textbox using jQuery. In jQuery we can restrict to user to cut, copy, paste options in Textbox easily by using simple code.


To disable cut, copy and paste functionality for the Textbox we need to write the code like as shown below


<script type="text/javascript">
$(function() {
$('#txtName').bind("cut copy paste", function(e) {
e.preventDefault();
});
});
</script>
If you want to see it in complete example write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Disable Cut, Copy and Paste Options in textbox using jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$('#txtName').bind("cut copy paste", function(e) {
e.preventDefault();
});
});
</script>
</head>
<body>
<div>
<input type="text" id="txtName" />
</div>
</body>
</html>
Live Demo

For live demo try to enter text in textbox


Enter Text:

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

9 comments :

Unknown said...

plz give some realtime example with solution on WCF it will help to prepare for interview .

Anonymous said...

i think its not working as i tried to do cut,copy with other textboxes in this page...same result i got...and when i selected text in the textbox...the cut and copy options were available...what is the code actually supposed to do?

Suresh Dasari said...

It's working fine. i have written code only for Live Demo Textbox not for all the textboxes in this page. Please test completly before post comments like not working...

Anonymous said...

Hi Suresh
How to add multiple text boxes to that function.
Could you please reply.

Unknown said...

Helpful for me ...thank u

Venkatesh Ekkaluri said...

sir how to change this into asp.net control....

pls respond me

Anonymous said...

sir,I need explanation for the above code because i selected the text and gave right click and then i cut the data and again copied it there so cut,paste r working

Anonymous said...

Its working fine..@venky just do like this for asp controls..

$(function () {
$("#<%=TextBox10.ClientID %>").bind("cut copy paste", function (e) {
e.preventDefault();
});
});

In the abouve 'TextBox10' is the id of asp textbox

Unknown said...

plz explain the above code

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.