Blog

Disable copy, paste, cut with jQuery in ASP.NET

By Maziyar Nazaryan Blogs | JQuery Jun 08, 2012
It is sometimes necessary to restrict users from copying content from web pages. Here we will see how to do that with jQuery.

Just follow the steps below:

1. Put : 

<script type="text/javascript">

2. Inside block script put $(document).ready(function() function

<script type="text/javascript">

$(document).ready(function() {

3. Can bind for cut , copy , paste for event handler to target textbox 

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste', // ClinetID properties : Gets the control ID for HTML markup that is generated by ASP.NET

4. Prevent behavior that include "copy, cut, paste " for this textbox

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste',

function(e) { e.preventDefault(); // default behavior disable

5. Showing alert that cut , copy , pastecut , copy , paste is disabled!

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste',

function(e) { e.preventDefault();

alert("cut , copy , paste disable !!!!!");

});

});

</script>


picsample.jpg


 

 


1 - put : 

<script type="text/javascript">

2 - inside block script put $(document).ready(function() function

<script type="text/javascript">

$(document).ready(function() {

3 - can bind for cut , copy , paste for event handler to target textbox 

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste', // ClinetID properties : Gets the control ID for HTML markup that is generated by ASP.NET

4 - prevent behavior that include " copy , cut , paste " for this is textbox

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste',

function(e) { e.preventDefault(); // default behavior disable

5 - show alert based on cut , copy , paste disable!

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste',

function(e) { e.preventDefault();

alert("cut , copy , paste disable !!!!!");

});

});

</script>

 

The End

picsample.jpg

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs