Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Link to Javascript in ascxLink to Javascript in ascx
Previous
 
Next
New Post
7/16/2007 2:40 AM
 

Hi everyone:

I'm developing a Custom Module and I need to insert some JavaScript code. The main problem I have is that, due to my company's inner "Programming Rules" I can't put the JavaScript code directly in the ascx, and it has to go in a .js file.

Here's where the problem comes. If I insert the code directly there's no problem at all, but if I use the typical "< script src="Path/File.js"..." it doesn't work and I can't reach the functions in the Js.

The first error I get shows when I try to call a Load function. I register the call to the function using a Page.ClientScript.RegisterStartupScript, and it crashes because it doesn't reach the function and shows the "Invalid object" error".

I'm quite sure I'm missing something, and it has to be with DotNetNuke ways of working, because the same code with the same path and JavaScript file works OK.

Could someone give me a hand on this?

 
New Post
7/16/2007 9:50 PM
 

 

I am not expert in this area but this works for me:

 

Page.ClientScript.RegisterClientScriptInclude(

"FileKey", DotNetNuke.Common.ResolveUrl("~/DesktopModules/ModulePath/File.js"))

Try registering it this way before you registerStartupScript.

Also I think the DNN ClientAPI might offer standard DNN-ways to manage scripts and such.....

 

 

 

 
New Post
7/17/2007 2:50 AM
 
Hi smcclure11:

Thanks for the reply. Just tested it and worked, although I had to alter the path a little bit. It's the ~ that messes things up a bit. I used the path:
"/DotNetNukeFolder/DesktopModules/ModulePath/JSFolder/File.js"
and it worked perfect.

Thanks again for the help.

May Luck be with you
 
New Post
7/17/2007 8:55 AM
 

I am glad it worked for. 

On the URL:

Did you use the ~ with the url wrapped in  DotNetNuke.Common.ResolveUrl(~URL)?  If not, I'd recommend trying again because if "/DotNetNukeFolder/" is your virtual folder (i.e. You're running on htttp://localhost/DotNetNukeFolder/) you may have trouble porting that to production where "/DotNetNukeFolder/" is no longer a part of your path.

If you did use DotNetNuke.Common.ResolveUrl(~URL), then I am not sure why it wouldn't work.

Regards,

Steve

 
New Post
7/18/2007 3:48 AM
 
Uhm... now that you mention it, while I was RTM and STW I got to a post where they suggested something like that, but not as a Page.ClientScript.RegisterStartupScript(...), just as a simple Me.ResolveUrl, maybe that's why it didn't work. I'll test it right now, gimme a minute....
...
....
......
...
........
.........
...... ... ... ....... ...
ding!

Worked smooth, thanks again smcclure11. The full instruction ended like this:
Page.ClientScript.RegisterClientScriptInclude("jsInclude",DotNetNuke.Common.ResolveUrl("~/DesktopModules/ModuleFolder/jsFolder/File.js"))
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Link to Javascript in ascxLink to Javascript in ascx


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out