So this error stopped my productivity for a good three hours today. Gotta love when that happens.
I’m sure there are many different ways to resolve this issue, but I didn’t see anyone with the same problem I was having, so I’m going to go ahead and post my experience and how I fixed it.
Background Info:
I have a page layout I needed to implement and it uses some rounded corners javascript. My web application uses a masterpage, which I keep in a folder at “~/Resources/MasterPages/”. I’m using themes, so my css and related files are in a theme folder.
My css designer packaged the css with two JS files, one “jquery-1.2.6.min.js” and the other “jquery.curvycorners.min.js”. There was also an in-line script that I put in my <head> section.
So yeah, It’s using some JQuery and some inline scripts, etc, to get some rounded corners to work on my page.
The error that drove me nuts:
Ok, so I hit Ctrl + F5 to see the new pretty layout. And I hit the error, “object expected.” which points me to the very first line of the in-line script. I try a million things—moving the scripts around to different folders, moving the placement of the script in the <head> section, etc, to no avail.
What was even more interesting:
Certain pages would load the script and show me curved corners just fine. Others would not. I would strip down the page to it being empty (just a blank content page) and 1 would render fine, and the other would generate an error. I had no idea why—what on earth was going on here?
A hint to fixing the error:
I did some reading after “googling” the error (sorry, Bing!) and discovered that most of these errors result from the jquery file not being properly loaded. Okay…that started to point me in the right direction but I still couldn’t figure out why it wasn’t pathing properly. I mean, I was doing as people said – I would drag the .js file into my designer and it would print out the proper path. (../../Resources/Scripts/jquery-1.2.6.min.js”) and still the error.
The lightbulb! I finally figured it out:
Okay, so maybe you figured it out before reading this paragraph, but it took me about 15 min for the lightbulb to go off. (It is Monday, after all.)
Turns out the way that the path only worked for pages that were nested the proper two folders down. All other pages (anything in the root level, or only 1 folder in) would give that “object expected” error.
So those two “identical” pages were not identical really, because one was in a ~/FirstFolder/ and the other was in ~/FirstFolder/SecondFolder/. So the secondfolder page worked, because it went back two folders to the root using the path ../../ but the first folder hit an error because it went back too far, then didn’t find the jquery script!
My temporary solution (just to test it out) was to upload my jquery to my server, and change my src of the scripts to a static full url (instead of a relative path). And voila, it worked!
Now I’m hunting for that ASP.Net method where I can convert a path like that into a server path. I’ll update once I find it.
Anyway, hope this helps someone out there. It certainly drove me crazy all day.