Javascript – “Sys.WebForms.PageRequestManagerServerErrorException: status code: 500”

asp.netasp.net-ajaxjavascriptupdatepanelwebforms

I am using an asp.net text box inside ajax update panel. If I enter &# in the textbox and press Save Button , it gives a javascript error

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500

Please help me why this error appears?

enter image description here

Best Answer

Probably ASP.NET Request Validation kicked in and detected a potentially dangerous request (the &# in the textbox value). This causes an HttpRequestValidationException to be thrown - hence the 500 HTTP code is returned by the UpdatePanel. The way I see it there are two ways to solve this problem:

  1. Validate the contents of the textbox and replace any potentially dangerous (HTML like) values.
  2. Disable request validation:

    <%@ Page ValidateRequest="false" %>

If you choose to disable request validation make sure that the value of this textbox is not output verbatim somewhere else in your application. Make sure you are using HttpUtility.HtmlEncode when displaying it in order to avoid XSS issues.