Try something like this:
In your AssemblyInfo.cs file, place the following:
[assembly: System.Web.UI.WebResource("AssemblyName.filepath.FileName.js",
"text/javascript")]
where AssemblyName is, for instance, MyNamespace.dll, so "MyNamespace", then
each folder nested within your assembly, e.g. in my project I have a folder
called "scripts", so filepath above would be "scripts", the result would be
"MyNamespace.scripts.MyFile.js".
Ensure in the file properties within Solution Explorer in VS that the Build
Type is "Embedded Resource" for the script file itself.
Finally, override the OnPreRender event in your control, add the following
(if you are going to be using a ScriptManager control/AJAX, otherwise use
Page.ClientScript... where you see ScriptManager:
// Register JavaScript
string jsPath = Page.ClientScript.GetWebResourceUrl(this.GetType(),
"Retina.Web.UI.Controls.FloatingMenu.FloatingMenu.js");
ScriptManager sm = ScriptManager.GetCurrent(this.Page);
ScriptReference sr = new ScriptReference(jsPath);
if (!sm.Scripts.Contains(sr))
sm.Scripts.Add(sr);
Hope that helps. Let me know if you have any questions or if anyone has a
more efficient way of doing this by all means...
--
Chad Scharf
_______________________________
http://www.chadscharf.com
cfps.Christian said:
I'm trying to have a javascript file included with my usercontrol, but
when the page loads it says that none of my JS methods are there.
What are the steps that I need to take to get a javascript file to go
with the user control so that I don't have to load the script onto the
page that is calling the control?