Monday, January 12, 2009

Don't take shortcuts on script tags!

This problem annoyed me for longer than I would have hoped recently - even though I have seen it before and spent a frustrating time 'fixing' it. I added a script reference (the first for the page) to the head of a html page and lazily wrote it as

<script type="text/javascript" src="scripts/jquery-1.3.1.js" />

Well this broke the ScriptManager, which couldn't hook up the postback methods for the UpdatePanels on the form. Hmm that's odd, even an empty .js file included this way cause a javascript error on page load such as "this._form is null" or "__doPostBack is not defined". And then something twigged from a not-so-distant project and there it was

<script type="text/javascript" src="scripts/jquery-1.3.1.js"></script>

Lesson: Don't take shortcuts when writing script tags!

More explanation of why

kick it on Shout it