Reputation: 151
When I input some html tag like < b>
or < test>
(without the space after "<") in my TextBoxes, When I submit the form I got the issue:
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server.
The status code returned from the server was: 500
I don't want to set the "ValidateRequest" false, because of security problems.
I thought in make some kind of javascript function inserting a space after "<", this could work...I guess.
Any idea?
Upvotes: 1
Views: 1891
Reputation: 6265
You can escape your input using javascript before posting it back.
See existing answers:
On the c# side use HttpUtility.HtmlDecode(string)
to decode your text back.
Upvotes: 2
Reputation: 16144
You can escape/unescape your html content using JavaScript (jQuery) as shown below:
<script>
function htmlEncode(value) {
return $('<div/>').text(value).html();
}
function htmlDecode(value) {
return $('<div/>').html(value).text();
}
</script>
Upvotes: 1