Click to See Complete Forum and Search --> : Master Pages And Linked JS files


wackoyacky
09-28-2006, 01:39 AM
Hi!
I'm using master pages in my applications. I import common css files and javascript files on my master pages since they will all be used on every page.

Everything works fine if the page that will be using the masterpage is in the same directory the master pages is in. But once, the page is already on other directories the link now to the js files are now broken. CSS file links were automatically updated but not the js files.

Any idea how to accomplish this or are there any work arounds?

Thanks,
Enzo

sirpelidor
09-28-2006, 03:16 AM
see if this (http://www.dotnetslackers.com/XML/re-17315_ASP_NET_2_0_Master_Pages_But_how_do_I_run_JavaScript_onLoad.aspx) helps....

wackoyacky
09-28-2006, 03:26 AM
Hi sirpelidor!

Sorry sir that link doesn't address my problem. My main problem is how would I able to update the javascript links on my masterpage as I go along different subdirectories in the application.

Thanks,
Enzo

sirpelidor
09-28-2006, 05:41 AM
sorry for not being clear in terms of instruction.

The linked I showed u, was assuming you have register the script "manually" in code. So you are basically repeating the code in all your aspx/controls. It is obviously a bad practice, but it works :P

There is another neat approach I've came across(I haven't tried, but the idea make sense to me), is to register your js in a server control.

Just like when you place images in masterpage that share across all sub folders:
<img src="~/image/someImage.jpg" runat="server" />

detail can be find here (http://extraview.co.uk/blog/PermaLink,guid,a4bd0a9a-6bdc-4552-a946-3a82af0afc89.aspx). Basically, you are letting asp.net server control to handle the path problem for you.

Let us know if it goes well for you.

Good luck

sirpelidor
09-28-2006, 11:40 AM
per post above, I just came across someone else who create their own server control and have javascript maps to it with source code.

this is a little more detail, see if it helps

http://markitup.com/Posts/Post.aspx?postId=5338c901-c910-4af0-bbca-6ae0067df759

wackoyacky
09-28-2006, 08:43 PM
Hi sirpelidor!

Thanks for the links. I'll try it on my free time later.

Thanks,
Enzo

wackoyacky
10-11-2006, 10:58 PM
I end up using Rick Strahl's workaround (using contentplace holder between head tags) but thanks for the links sirpelidor it would come in handy when I have the luxury of time to do the codings. Thanks.