Wednesday, 2 July 2008

ASP.NET ScriptManager causing JavaScript errors

First post for a while and the reason I'm getting this out there is due to the lack of Google results on the subject.

Recently our QA dept raised a bug with 2 javascript errors appearing on certain pages. The errors itself is 'Sys is not defined' which in itself is a really useless error. Just to give this some background, I was using a .NET ScriptManager on a masterpage. Some pages using this masterpage had the JS errors and some didn't.

sys not defined error

Further investigation lead me to believe the errors were caused by the webresource.axd and scriptresource.axd not being rendered in the HTML. I was expecting something like this:
<script src="/WEBSITE/WebResource.axd?d=-LVZ..."

<script src="/WEBSITE/ScriptResource.axd?d=IrhmF..."
After spending a few hours googling the issue I found a few responses suggesting IIS (deselect 'check file exists', yes done that), or web.config entries (again all correct).

Finally I stumbled upon a thread suggesting .NET pages using ScriptManagers can cause issues when not calling the base from any page events - I've since lost the link hence this post!

This is how my code looked with the error:

protected override void OnPreRenderComplete(EventArgs e)


The fix is obvious now - use base.OnPreRenderComplete(e) but for future reference if you experience this issue check all your events are calling base correctly.


Blogger brian.brackeen said...

After two to three hours of searching I stumble across this post and it solved my issue. I wasn't calling the base method at all. Once I did this, boom worked. Wow, something so simple causes so much time loss.

18 October 2009 at 18:34  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home