There is a nice solution to accomplish what I am after here, where they use this javascript function:
var text = document.getElementById('txtText');
text.addEventListener('input', function(e){
var keyCode = e.keyCode ? e.keyCode : e.which;
this.value = this.value.replace(/\s/g, '')
if(keyCode === 32) return;
})
which is applied to the following element:
<input type='text' id="txtText">
In my case, I don't have an <input...
element, but an <asp:TextBox
element, and the function above isn't working. I am using the correct element ID but I can still paste and also type white spaces. What am I missing?