Javascript files

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

Can you embed .js files when you compile a site into dll's? Is this option
only available when compiling controls, or is it simply not possible at all?

Many thanks,
JJ
 
Hi, JJ

Yes, it's possible.

The problem is that you 'll need to refer your JS files through the
GetWebResourceUrl method of the ClientScriptManager object.

So you'll have to change every reference to the JScripts files to
something like:

<script type="text/javascript" src="<%=
ClientScriptManager.GetWebResourceUrl(this.GetType(),
"YOUR_RESOURCE_NAME.js") %>"></script>

Regards,

Paulo Santos
http://pjondevelopment.50webs.com
 
I'm not actually utilising AJAX here - just using javascript to do some
'live' image editing and sending some variables to a handler (see my other
question). The javascript runs when the document is loaded.

Is there atill a way to enbed the files so they don't appear as separate .js
files?

Thanks,
JJ
 
The point is that it's not AJAX.

If you embed the JS (adding a WebResource attribute in the assembly
and all that) you still need to reference the file as stated.

That's because an embeded script is a resource, and in order to access
a resource, you need to call the GetWebResourceUrl() method.

It's quite simple.

Regards,

Paulo Santos
http://pjondevelopment.50webs.com
 
Ah... I see. Sorry I saw the ClientScriptManager object and jumped to the
wrong conclusion.

Thanks,
JJ
 
Just as an additional note, you don't *have to* use the GetWebResource
directive with an embedded resource such as a Javascript .js file. You can
still use the GetManifestResourceStream method of the Assembly class on the
GetExecutingAssembly method of Reflection, if it better suits your needs. You
can then emit the javascript into the page.
--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com
 
Back
Top