Geeks With Blogs
Create Fun Things - Samer's Developer Blog Development Blog for C#, .NET and Obj-C

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.

Posted on Monday, October 26, 2009 3:17 PM | Back to top


Comments on this post: Fixing Error: Microsoft JScript runtime error: Object expected

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
plz give reply
Left by suresh on Nov 11, 2009 1:15 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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
Left by waleed on Dec 02, 2009 4:56 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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?
Left by Javier Rigoni on Dec 09, 2009 8:23 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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?
Left by SamerPaul on Dec 11, 2009 9:29 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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
Left by javier on Dec 13, 2009 5:59 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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.
Left by Krupali. on Jun 03, 2010 2:55 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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
Left by Dottie on Feb 03, 2011 11:41 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
I was getting this same error, only in IE an could not resolve it until I found the solution here. Thanks a lot.
Left by Faizan on May 31, 2011 2:51 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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;
});
});
Left by novia on Jun 22, 2011 4:46 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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
Left by Jie Zhang on Jun 24, 2011 9:09 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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. :)
Left by Michal Zak on Aug 19, 2011 4:27 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
My Computer give error
please steerage me
Message: Object expected
Line: 16
Char: 16812
Code: 0
Left by sina on Dec 11, 2011 11:08 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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>
Left by bhaklu on Jan 05, 2012 12:47 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
you just saved my life !!! :)
Left by Maher on Feb 14, 2012 7:22 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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.
Left by vinod on Feb 20, 2012 10:15 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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))""

Left by vinod on Feb 20, 2012 10:20 PM

# Microsoft JScript runtime error: Object expected solution
Requesting Gravatar...
please solution JScript error.
Left by vikas on Feb 25, 2012 4:46 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
you saved my 3-4 hours. thanks
Left by dulari on Apr 20, 2012 1:08 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
images not seen jscript runtime showing error
Left by prashant on Aug 09, 2012 6:56 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
sasdaad sefseaf
Left by dd on Aug 21, 2012 5:08 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
facing same issue... getting runtime exception... what to do...Help!!!!
Left by amy on Aug 23, 2012 2:27 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
gr8 my bulb lighted within 10 mints while reading ur post ....
Left by NaiveDeveloper on Aug 28, 2012 9:33 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
Thanks a lot...u fixed my problem!
Left by Ravi on Sep 07, 2012 12:05 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
But WHY is this happening? No one explaining that? Why can't it find the root directory when technically it should?
Left by Nancy on Oct 10, 2012 6:27 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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
Left by Rose on Oct 21, 2012 10:36 PM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting Gravatar...
yea.a step by step guide would be kind.thanks guys
Left by beginner on Mar 08, 2013 9:37 AM

# re: Fixing Error: Microsoft JScript runtime error: Object expected
Requesting 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
Left by kenny on Aug 13, 2013 12:59 PM

Your comment:
 (will show your gravatar)


Copyright © samerpaul | Powered by: GeeksWithBlogs.net | Join free