I have a asp.net TextBox control and I want to be able to capture a paste event, clean the text that is paste by the user and show the end result in the TextBox control. I have tried many different ways and yet none are working as intended.
<asp:TextBox ID="editor">...</asp:TextBox>
I need a solution that works in all browsers.
I am working with something like this right now.
$(document).ready(function() {
var $editor = $('#editor');
/// Control used for testing, the control with ID editor will be overwritten
/// with the cleaned text.
var $clipboard = $('<textarea />').insertAfter($editor);
$editor.on('paste, keydown', function() {
var $self = $(this);
setTimeout(function(){
var $content = $self.text();
$clipboard.val($content);
},100);
});
});
If editor is the ID of a div tag, this works perfectly but if editor is the ID of a TextBox control, this does not work. I get the old contents of the TextBox and not what was paste in by the user.
Can anyone explain why this above code works one a DIV tag but not on the TextBox control?