Follow @RoyOsherove on Twitter

Problem and solution: Renaming htm file to aspx may cause javascript trouble

We ran across this when moving some old files to a new project. One of the tasks was to turn a very simple htm file into the same file with an aspx extension.

 

The original htm file had a reference to a javascript file. The trouble was that the new aspx file would not respond to the javascript events that the original htm file referenced (and worked perfectly with). The javascript in question was a calender widget that would appear on a button click on the page.

We narrowed it down to reproduce the problem with a simple 5 line htm file which worked. and a renamed version of the htm file as an aspx file which did not work. After some clues from Mike Gunderloy I enabled script debugging on my machine and saw that we were getting an error from a specific line in the js file. The error was:

Line: 63
Error: Unterminated string constant

Looking at that line in the script reveals something strange (looking inside the debugger):

63:  es : 'Presione para seleccionar un a??

64: de : 'Klicken um Jahr auszuwählen',

so the string in line 63 was not closed because it was corrupt. There should have been a ', there like this:

  es : 'Presione para seleccionar un año',

Looking at the direct source I could see that the text was not corrupt so this was coming from the browser! even more, this worked in the original htm version of the file. After some more clues from Mike it appears that the character set in the js source was not recognized using the aspx file. Translation: the aspx file was using a code page that did not include the letters at the end of the sentence in the js source file, so it thought it was corrupt and everything got screwed up.

The solution to this is pretty simple. Make the code page for the aspx file into code page 1252 by adding it in the page declaration tag:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="calTest.aspx.vb" Inherits="calTest.WebForm1" codepage="1252"%>

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="calTest.aspx.vb" Inherits="calTest.WebForm1" %><%@ Page Language="vb" AutoEventWireup="false" Codebehind="calTest.aspx.vb" Inherits="calTest.WebForm1"  codepage="1252" %>

Now the page can recognize the characters and all is right again in the world.

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="calTest.aspx.vb" Inherits="calTest.WebForm1" %>

The idiot's guide to O/R mappers

A New Source Control system