I was working with a project that uses the concept of master page. Within the master page I have a bunch of UserControls for some specific purposes and one of the UserControl is for the site dynamic menu. The menu was basically built using JQuery and CSS. The menu works fine if you are using it as an anonymous user but if you logged in as authorize user the menu will no longer work for some odd reasons and produces the following script error below in the browser:
Message: Object expected
Here's how I referenced the JQuery script within the UserControl:
//do stuffs here
Again, the code above works only for public pages but not for secured pages after you logged in as valid user. After digging through the codes and after doing a thorough investigation, I found out that the "Object Expected" error occurs when you try to access an object which is not defined, not referenced or mistakenly misspelled. First I'm guessing that when navigating to the secured pages the previous script reference fails to locate the actual path of the JQuery script that's why in error above, Line 122 refers the $(document).ready(function().
Luckily, ASP.NET's Control class provides the handy ResolveUrl method that lets you easily use and parse relative URLs. ResolveUrl fixes up urls that start with ~ and puts the applications relative root path in its place. So to fix the issue you can use ResolvedURL for referencing the path like:
That's it! I hope you'll find this post useful!