Back to top

ASP.NET WebForms ScriptResource error

You know those days when you wonder how you stay sane in this line of work?! I’ve just come across a little gotcha that I’ve just spent almost an hour trying to nut out, so thought I’d share a potential time saver with others!

It’s one of those red-herring cases. You get an error and it turns out to be quite unrelated to the underlying issue. In this case, it’s the following beauty which surfaced for me when a submit button was clicked on a form:

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

This is the error showing up in the Chrome Developer Tools, and the file it occurs in is ScriptResource.axd.

As far as the end user is concerned, nothing has happened, and the browser doesn’t appear to have responded to their click. What is actually happening here behind the scenes is that the server is throwing a 500 error, and this is not being handled well by the Microsoft AJAX library that is performing the ajax call to submit the form.

One way to find the underlying cause of error is to check the Event Viewer on the web server (if you have this access), to find the error/warning being raised.

If you don’t have this access, though (or if you forget about the Event Viewer in the first instance, like I did!), the way I dug in to find the actual error was by temporarily turning off partial rendering, by setting EnablePartialRendering to false on my ScriptManager:

<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="false" runat="server"></asp:ScriptManager>

I was then able to view the details of the actual error message (I have CustomErrors turned on for RemoteOnly, so I reproduced it locally on the server), and saw the issue was a null value being passed to a database table that wasn't expecting null (oops!) in the button processing code. So I fixed the issue and hey presto, issue resolved!

I hope this helps someone, there tends to be a lot of issues of this nature raised out there on Stack Overflow, MSDN etc but because this error is actually just reflecting the fact that a 500 error was thrown on the server during an AJAX call, you can get bogged down very quickly in completely unrelated causes and solutions.