Joseph Jones
asked on
How to solve object required error when calling java script from script folder?
Hi
I have developed a website with a master page which has menus to navigate to different pages. I have written the following code to hide and show the menus. It works fine on my developer machine but I get "object required" error message on the production server.
I call the js code from the script folder in ASP.NET 4 website.
Can you please help?
Thanks
Jose
]This is called from the maste page:
<!--BEGIN TO NAVIGATE-->
<script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/ JoeNavigat ion.js") %>'>/</script>
<!--END TO NAVIGATE-->
This list is for Menus:
<div id="menu">
<ul>
<li><a href="<%=Request.Applicati onPath%>/D efault.asp x" accesskey="1" title="" id="Home">Home</a></li>
<li><a href="<%=Request.Applicati onPath%>/Q uickQuery. aspx" accesskey="2" title="" id="QuickQuery">Quick Query</a></li>
<li><a href="" accesskey="3" title="" id="GRRAdmin">GRR Admin</a></li>
<li><a href="<%=Request.Applicati onPath%>/A bout.aspx" accesskey="4" title="" id="About">About</a></li>
<li><a href="<%=Request.Applicati onPath%>/H elp.aspx" accesskey="5" title="" id="Help">Help</a></li>
<li><a href="" accesskey="6" title="" id="UserLoginDisplay">Logi n</a></li>
<li><a href="<%=Request.Applicati onPath%>/C hangePassw ord.aspx" accesskey="7" title="" id="ResetPassword">Reset Password</a></li>
</div>
This Java script code is saved with .js extention in "script" folder:
//BEGIN MENU NAVIGATIONS
function HideMyAdmin() {
document.getElementById("M yAdmin").s tyle.displ ay = "none";
document.getElementById("R esetPasswo rd").style .display = "none";
}
function HideMyAdminAndLogin() {
document.getElementById("M yAdmin").s tyle.displ ay = "none";
document.getElementById("U serLoginDi splay").st yle.displa y = "none";
document.getElementById("R esetPasswo rd").style .display;
}
function ShowMyAdmin() {
document.getElementById("U serLoginDi splay").st yle.displa y = "none";
document.getElementById("R esetPasswo rd").style .display
}
function HideALL() {
document.getElementById("M yQuery").s tyle.displ ay = "none";
document.getElementById("M yAdmin").s tyle.displ ay = "none";
document.getElementById("R esetPasswo rd").style .display = "none";
}
function HideLogin() {
document.getElementById("U serLoginDi splay").st yle.displa y = "none";
}
function HideForChangePw() {
document.getElementById("M yAdmin").s tyle.displ ay = "none";
document.getElementById("U serLoginDi splay").st yle.displa y = "none";
}
//END
I have developed a website with a master page which has menus to navigate to different pages. I have written the following code to hide and show the menus. It works fine on my developer machine but I get "object required" error message on the production server.
I call the js code from the script folder in ASP.NET 4 website.
Can you please help?
Thanks
Jose
]This is called from the maste page:
<!--BEGIN TO NAVIGATE-->
<script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/
<!--END TO NAVIGATE-->
This list is for Menus:
<div id="menu">
<ul>
<li><a href="<%=Request.Applicati
<li><a href="<%=Request.Applicati
<li><a href="" accesskey="3" title="" id="GRRAdmin">GRR Admin</a></li>
<li><a href="<%=Request.Applicati
<li><a href="<%=Request.Applicati
<li><a href="" accesskey="6" title="" id="UserLoginDisplay">Logi
<li><a href="<%=Request.Applicati
</div>
This Java script code is saved with .js extention in "script" folder:
//BEGIN MENU NAVIGATIONS
function HideMyAdmin() {
document.getElementById("M
document.getElementById("R
}
function HideMyAdminAndLogin() {
document.getElementById("M
document.getElementById("U
document.getElementById("R
}
function ShowMyAdmin() {
document.getElementById("U
document.getElementById("R
}
function HideALL() {
document.getElementById("M
document.getElementById("M
document.getElementById("R
}
function HideLogin() {
document.getElementById("U
}
function HideForChangePw() {
document.getElementById("M
document.getElementById("U
}
//END
1. What line are you getting the error?
2. <script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/ JoeNavigat ion.js") %>'>/</script>
What does this line render in the actual page?
3. <a href="<%=Request.Applicati onPath%>/D efault.asp x" accesskey="1" title="" id="Home">Home</a>
What does this render?
2. <script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/
What does this line render in the actual page?
3. <a href="<%=Request.Applicati
What does this render?
Lines from your question part:
1. I call the js code from the script folder in ASP.NET 4 website.
2. script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/JoeNavigation.js") %>'>/</script>
This Java script code is saved with .js extention in "script" folder
So let us know is the javascript file is in script folder? If yes change the folder name to Scripts because the same javascript file is not accessible as per 2nd point.
Share back whether it helped or not.
1. I call the js code from the script folder in ASP.NET 4 website.
2. script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/JoeNavigation.js") %>'>/</script>
This Java script code is saved with .js extention in "script" folder
So let us know is the javascript file is in script folder? If yes change the folder name to Scripts because the same javascript file is not accessible as per 2nd point.
Share back whether it helped or not.
ASKER
Hi Informaniac,
1) The error is : "ReferenceError: HideGRRAdmin is not defined"
2) This code renders in Login.aspx page (which uses the master page)
3) Actually, the default page is not the loading page but the login.aspx page.
Thanks
Joe
1) The error is : "ReferenceError: HideGRRAdmin is not defined"
2) This code renders in Login.aspx page (which uses the master page)
3) Actually, the default page is not the loading page but the login.aspx page.
Thanks
Joe
The error is : "ReferenceError: HideGRRAdmin is not defined"
I think you are calling js function HideGRRAdmin() from some part of your page. But it has been not defined in your javascript file.
Could you please ensure the same?
I think you are calling js function HideGRRAdmin() from some part of your page. But it has been not defined in your javascript file.
Could you please ensure the same?
ASKER
Hi
I am sorry the error is: " ReferenceError: HideMyAdmin is not defined"
Following is one of the functions that is written in js script called "JoeNavigation.js" which is located on the Script folder as mentioned in earlier post.
function HideMyAdmin() {
document.getElementById("M yAdmin").s tyle.displ ay = "none";
document.getElementById("R esetPasswo rd").style .display = "none";
}
I am sorry the error is: " ReferenceError: HideMyAdmin is not defined"
Following is one of the functions that is written in js script called "JoeNavigation.js" which is located on the Script folder as mentioned in earlier post.
function HideMyAdmin() {
document.getElementById("M
document.getElementById("R
}
OK. To test with if the javascript file is accessible and working fine or not. Could you please write line in top of js file as:
alert("Called from JoeNavigation.js file");
Do you able to see the above message while running your application?
alert("Called from JoeNavigation.js file");
Do you able to see the above message while running your application?
ASKER
Hi,
No. I couldn't get the alert message. It is weired.
I get the same error message:
"ReferenceError: HideMyAdmin is not defined"
No. I couldn't get the alert message. It is weired.
I get the same error message:
"ReferenceError: HideMyAdmin is not defined"
ASKER
Hi,
The function "HideMyAdmin" is called on the page load event of Login.aspx page.
'== begin to hide Myadmin menu
Dim joescript As String = "joescript"
Page.ClientScript.Register StartupScr ipt(Me.Get Type(), joescript, "HideMyAdmin()", True)
'== end to hide Myadmin menu
The function "HideMyAdmin" is called on the page load event of Login.aspx page.
'== begin to hide Myadmin menu
Dim joescript As String = "joescript"
Page.ClientScript.Register
'== end to hide Myadmin menu
ASKER
Hi,
I don't even get the alert message on my desktop but the "HideMyAdmin()" function still works fine on my desktop but not on the production server It is too weird for me now...
I don't even get the alert message on my desktop but the "HideMyAdmin()" function still works fine on my desktop but not on the production server It is too weird for me now...
We would try to get solution for same. But before that could you please answer few questions:
Q.1. In which folder (script or scripts) the JoeNavigation.js script file is?
Q.2. See your page's source code from browser and get the following line's output:
<!--BEGIN TO NAVIGATE-->
<script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/ JoeNavigat ion.js") %>'>/</script>
<!--END TO NAVIGATE-->
I still believe that src line's display would be different from the one displayed on your desktop.
Q.1. In which folder (script or scripts) the JoeNavigation.js script file is?
Q.2. See your page's source code from browser and get the following line's output:
<!--BEGIN TO NAVIGATE-->
<script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/
<!--END TO NAVIGATE-->
I still believe that src line's display would be different from the one displayed on your desktop.
Check if the js file is sent to your browser from your webserver.
You can check in your browser by typing in the location of the js-file in the address bar.
NB: If you use IIS7, make sure that static content is being handled.
Check via Control Panel -> Programs & Features -> Turn Windows features on or off -> Internet Information Services -> World Wide Web Server -> Common HTTP Features.
Make sure Static Content is checked.
You can check in your browser by typing in the location of the js-file in the address bar.
NB: If you use IIS7, make sure that static content is being handled.
Check via Control Panel -> Programs & Features -> Turn Windows features on or off -> Internet Information Services -> World Wide Web Server -> Common HTTP Features.
Make sure Static Content is checked.
include a document ready function and wrap it around your hole JoeNavigation.js script like this:
if (document.readyState === "complete") { /*joeNavigation function here...*/ }
ASKER
Hi,
I tried the document ready function and it is still the same problem. I browed the file from the address bar, it brings the file without any problem. The path of the file is the same as in view source as well.
Following is the error message from my localhost.
Please have a look,
Thanks
Joe
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0E; InfoPath.3; Zune 4.7; .NET4.0C)
Timestamp: Thu, 30 Aug 2012 23:57:18 UTC
Message: Object expected
Line: 384
Char: 1
Code: 0
URI: http://localhost/MyWebvNET/Login.aspx
I tried the document ready function and it is still the same problem. I browed the file from the address bar, it brings the file without any problem. The path of the file is the same as in view source as well.
Following is the error message from my localhost.
Please have a look,
Thanks
Joe
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0E; InfoPath.3; Zune 4.7; .NET4.0C)
Timestamp: Thu, 30 Aug 2012 23:57:18 UTC
Message: Object expected
Line: 384
Char: 1
Code: 0
URI: http://localhost/MyWebvNET/Login.aspx
If possible could you share your Login.aspx, Master page and javascript file for testing the problem. As it is hard to debug problem without actually looking all details.
Again if it is confidential please do not share.
Again if it is confidential please do not share.
ASKER
Hi,
I am very sorry, I am not in a position to share the pages.
Thanks
Joe
I am very sorry, I am not in a position to share the pages.
Thanks
Joe
Maybe you didn't understand quite well. I meant to modify the JoeNavigation.js, so it's functions are wrapped into the document ready if clause. Did you do that?
Ok, so there must be an error in your js-file.
According to tour post, the ShowMyAdmin method has an invalid statement.
It's a useless statement anyway, you probably want to set it to"none"?
According to tour post, the ShowMyAdmin method has an invalid statement.
function ShowMyAdmin
document.getElementById("UserLoginDisplay").style.display = "none";
document.getElementById("ResetPassword").style.display
}
The semi-colon on the second line is missing.It's a useless statement anyway, you probably want to set it to"none"?
1. Could you modify this line:
by
I know both work same way. But can you give it try.
2. Are you using ajax in your application?
<script type="text/javascript" src='<%= Page.ResolveUrl("/Scripts/JoeNavigation.js") %>'>/</script>
by
<script type="text/javascript" src='<%= Page.ResolveClientUrl("/Scripts/JoeNavigation.js") %>'>/</script>
I know both work same way. But can you give it try.
2. Are you using ajax in your application?
ASKER
Hi
I have set document.getElementById("R esetPasswo rd").style .display = "none" and changed
Page.ResolveUrl to Page.ResolveClientUrl. I still get the same error message.
I did wrap the JoeNavigation.js function with document.readyState == "complete".
Yes. I am using Telerik asp.net ajax controls in my application.
Thanks
Joe
I have set document.getElementById("R
Page.ResolveUrl to Page.ResolveClientUrl. I still get the same error message.
I did wrap the JoeNavigation.js function with document.readyState == "complete".
Yes. I am using Telerik asp.net ajax controls in my application.
Thanks
Joe
ASKER
All the functions in JoeNavigation.js works fine if they are put in master page even on production server. But it doesn't like to be called from the Script folder.
Thanks
Joe
Thanks
Joe
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi vs00saini
That Ellipsis made the magic. It works fine now.
<script type="text/javascript" src="<%= Page.ResolveUrl("~")%>Scri pts/JoeNav igation.js "></script >
You are a Star,
Thanks for time and help,
Cheers,
Joe
That Ellipsis made the magic. It works fine now.
<script type="text/javascript" src="<%= Page.ResolveUrl("~")%>Scri
You are a Star,
Thanks for time and help,
Cheers,
Joe
Hi Joe,
I am double happy as all efforts went towards fruitful success. Happy coding :)
I am double happy as all efforts went towards fruitful success. Happy coding :)
We can not trace your issue.
Better way, you can solve this yourself.
Open same URL in Mozilla Firefox. Open Firebug add on for Firefox. and just refresh page once.
In Firebug window, in Console tab, you will get exact error, what is missing and which object is not found.
Hope this helps you.