1

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?

Anas
  • 5,622
  • 5
  • 39
  • 71
williancsilva
  • 151
  • 1
  • 3
  • 12

2 Answers2

2

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.

Community
  • 1
  • 1
Anri
  • 6,175
  • 3
  • 37
  • 61
1

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>
Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52