ASP-Microsoft JScript runtime error: Object expected.

arvee2003 used Ask the Experts™

Using vs2008 and c#.

In my development enironment I have 2 website with identical folder structure. And my master pages for
both website are almost similar.

In both the application I have some javascript referenced for counting the number of characters entered as follows:

 <script type="text/javascript" src='<%# Page.ResolveUrl("~/Javascript/textcounter.js") %>'> </script>

It works perfectly fine in one website. However in the other website onkeypress it was trying the javascript function
and it gives the following error.
      Microsoft JScript runtime error: Object expected

I am not sure why it is working on one website and not on the other.

Both VS2008 and the 2 website are all on the same machines.

Looks like it is something specific to a website.

This happens when debugging application using IE. When I ran in Chrome it is not displaying the error.

Is there any issues in webconfig files? All my reference are ok.

It is was working ok 2 days ago and I did not install anything.

Any input is appreciated.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
checl whether u have the js file in ur second website at correct location.


Yes. In both the websites I have a folder javascript under my app root directory and it is in there
According to me:

It seems that the JS files are ok, but the page on which it is applied may be missing some element like any id which is used in JS file.

By the way, if you use FIREFOX and FIREBUG addin, it would help you a great. It will provide the exact line in the JS file where the error occurs while applying javascript debugging on. Believe me, it would be the best solution to find out and solve out your problem. It's great tool!

Let me know if you any difficulty.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.


The code is same in both the websites. It is a problem with IE 8 which was working before
Looks like its unable to resolve the path.

 <script type="text/javascript" src='<%# Page.ResolveUrl("~/Javascript/textcounter.js") %>'> </script>
The above is in master page.

If I look my source code is shows as follows
 <script type="text/javascript" src=''> </script>

Something is messed up in some page. I am not sure where.

But the same thing is in other website on the same machine which works. Are there
website references for javascript or it has something to do with Ajax client



One more thing. My website root is helpdesk.

If I replace this

 <script type="text/javascript" src='<%# Page.ResolveUrl("~/Javascript/textcounter.js") %>'> </script>

<script type="text/javascript" src='/helpdesk/Javascript/textcounter.js") %>'> </script>

it works. No errors

Is there an issue with Page.ResolveUrl method which works in one website and not in other

It should work:

<script type="text/javascript" src='<%= Page.ResolveUrl("~/Javascript/textcounter.js") %>'> </script>


<script type="text/javascript" src='<%= Page.ResolveUrl("Javascript/textcounter.js") %>'> </script>
should be


It works.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial