I want to achieve something like this but for mvc3, where user can't either copy/paste or use CTRL+C/CTRL+V on the text field.
How to disable copy and cut in TextBox?
Thanks for your help.
I want to achieve something like this but for mvc3, where user can't either copy/paste or use CTRL+C/CTRL+V on the text field.
How to disable copy and cut in TextBox?
Thanks for your help.
As much as I love jQuery, it's totally unnecessary as you can do it right in the Html.Textbox call like so:
Html.TextBox("Test", null, new { oncopy= "return false", onpaste="return false"})
in a word, you can't totally as the user can easily disable javascript. however, assuming that many of your users may not be savvy to this, then you can use jquery to achieve this:
$("#textA").bind('copy', function() {
alert('copy behaviour detected!')
});
$("#textA").bind('paste', function() {
alert('paste behaviour detected!')
});
or all in one:
$('#textA').live('copy paste cut',function(e)
{
e.preventDefault();
});
you can then build on this of course and prevent the user from achieving those actions, see:
http://www.cjhubbard.com/code/disabling-copypaste-for-your-form-using-jquery/
$(function () {
$('elementId').bind('cut copy paste', function (e) {
e.preventDefault();
alert("YOU SHALL NOT PASte!!!");
});
});
You can use this function for any element, calling it by Id