I have a textfield which displays a string which contains < and >. The code throws an error because of that. How can I allow the usage of those chars in my textfield?
The easiest solution is to disable request validation in single pages
<%@ Page ... ValidateRequest="false" %>
but don't forget to enable requestValidationMode="2.0"
...
This solution could espose some threats.
Another smart solution is to replace via javascript text written by user to make it safe for validation:
is considere dangerous, but < tag>
is considered safe!
A javascript replacement can solve the problem.
function validateTxt() {
$("textarea, input[type='text']").change(function () {
html = $(this).val(); //get the value
//.replace("a" , "b") works only on first occurrence of "a"
html = html.replace(/< /g, "<"); //before: if there's space after < remove
html = html.replace(/