Fixing Error: Microsoft JScript runtime error: Object expected

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.

Print | posted on Monday, October 26, 2009 3:17 PM

Feedback

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by suresh at 11/11/2009 1:15 AM Gravatar
plz give reply

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by waleed at 12/2/2009 4:56 PM Gravatar
Asp.net Master page and JQuery reference – JS Inside Master Pages:
http://ledomoon.blogspot.com/2009/12/aspnet-master-page-and-jquery-reference.html

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Javier Rigoni at 12/9/2009 8:23 PM Gravatar
Hi there,

I guess I have the same problem with the curvycorners, and I tried the same solution but didn t work.
I made the static full url for the jquery and also for the curvycorners.js but still with problems in internet explorer.

Any idea?

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by SamerPaul at 12/11/2009 9:29 AM Gravatar
Did you try the solution in the comment above yours? (using ResolveURL in the MasterPage).

Also, I'd check what version of jquery is being used and make sure it's the most up-to-date one.

Other than that, I'm not sure what might be wrong off the top of my head--maybe the order in which the page is being parsed is incorrect?

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by javier at 12/13/2009 5:59 PM Gravatar
Thank you for your reply.

yes I tried all the posibilities and I couldn t get to the solution.
my jquery version is jquery-1.3.2.min.js so I guess is the last one right?
perhaps i am not doing well the path.
Could you please show me the path you used?

Thank you very much

Javier

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Krupali. at 6/3/2010 2:55 PM Gravatar
Thanks you for the solution, I was struggling with the same issue, am glad you took the time to post your solution. Appreciate it.

Krupali.

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Dottie at 2/3/2011 11:41 AM Gravatar
When I go into a game room on Pogo.com I get a couple, three "object expected" windows....Can someone please tell me how to fix this error?

Thanks

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Faizan at 5/31/2011 2:51 AM Gravatar
I was getting this same error, only in IE an could not resolve it until I found the solution here. Thanks a lot.

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by novia at 6/22/2011 4:46 AM Gravatar

jQuery(function($) {
$('#basic-modal .basic').click(function(e) {
$('#basic-modal-content').modal();

return false;
});
$('#basic-modal1 .basic').click(function(e) {
$('#basic-modal-content1').modal();

return false;
});
$('#basic-modal2 .basic').click(function(e) {
$('#basic-modal-content2').modal();

return false;
});
$('#basic-modal3 .basic').click(function(e) {
$('#basic-modal-content3').modal();

return false;
});
});

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Jie Zhang at 6/24/2011 9:09 AM Gravatar
If you have several .js file need to insert into the index.aspx,try to change the order of these js file because the page want to load these JS with correct order

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Michal Zak at 8/19/2011 4:27 AM Gravatar
Samer, you save the day! Thx for this solution about the jquery loading failure. I also run with this problem today but now I have solved.
One way that I have been able to get the permanent URL via ASP.NET and then give to the html where the jquery process the html was to do the following:

string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
string webTarget = baseUrl + "/modules/Help/MainHelp.aspx";

With this, you will get always the same URL no matter at which location of your website you are. :)

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by sina at 12/11/2011 11:08 AM Gravatar
My Computer give error
please steerage me
Message: Object expected
Line: 16
Char: 16812
Code: 0

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by bhaklu at 1/5/2012 12:47 AM Gravatar
I faced the same issue and solved it just by changing the way i am including my jQuery reference.
In case of any jQuery application, always include the script tag of jquery first then any other reference related to your application.

<head id="Head1" runat="server">
<title></title>
<script src="Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="Scripts/zingchart-html5beta-min.js" type="text/javascript"></script>
<script src="Scripts/md5-min.js" type="text/javascript"></script>

<script src="Scripts/license.js" type="text/javascript"></script>
<%--<link href = "style.css" rel = "stylesheet" type = "text/css" />--%>
</head>

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Maher at 2/14/2012 7:22 PM Gravatar
you just saved my life !!! :)

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by vinod at 2/20/2012 10:15 PM Gravatar
Microsoft JScript runtime error: Object expected


i have old code,while running this code ,

i am getting this error,
please guide me to resolve this isse.

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by vinod at 2/20/2012 10:20 PM Gravatar
<input type="image" name="ctl00$cphMain$gridPrograms$ctl02$imgBtnEdit" id="ctl00_cphMain_gridPrograms_ctl02_imgBtnEdit" src="../Inc/Images/Others/Edit.gif" onclick="runwait();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$cphMain$gridPrograms$ctl02$imgBtnEdit&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" style="border-width:0px;" />

getting error in

onclick="runwait();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$cphMain$gridPrograms$ctl02$imgBtnEdit&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))""

# Microsoft JScript runtime error: Object expected solution

left by vikas at 2/25/2012 4:46 AM Gravatar
please solution JScript error.

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by dulari at 4/20/2012 1:08 PM Gravatar
you saved my 3-4 hours. thanks

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by prashant at 8/9/2012 6:56 AM Gravatar
images not seen jscript runtime showing error

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by dd at 8/21/2012 5:08 AM Gravatar
sasdaad sefseaf

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by amy at 8/23/2012 2:27 AM Gravatar
facing same issue... getting runtime exception... what to do...Help!!!!

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by NaiveDeveloper at 8/28/2012 9:33 AM Gravatar
gr8 my bulb lighted within 10 mints while reading ur post ....

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Ravi at 9/7/2012 12:05 AM Gravatar
Thanks a lot...u fixed my problem!

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Nancy at 10/10/2012 6:27 PM Gravatar
But WHY is this happening? No one explaining that? Why can't it find the root directory when technically it should?

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by Rose at 10/21/2012 10:36 PM Gravatar
When I go into a game room on Pogo.com I get three "object expected" windows....Can someone please tell me how to fix this error? Step by step.
Thanks

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by beginner at 3/8/2013 9:37 AM Gravatar
yea.a step by step guide would be kind.thanks guys

# re: Fixing Error: Microsoft JScript runtime error: Object expected

left by kenny at 8/13/2013 12:59 PM Gravatar
hi eyeryone

i getting this problem too.. microsof javascript runtime error and appear object expected .

can i have the solution ?

thanks

Best Regards,
Kenny Lee
Post A Comment
Title:
Name:
Email:
Comment:
Verification: