Hi,
You can refer the following way to call the js file in your server control.
Suppose we have two projects in Visual Studio. One is WebSite project (WebSite1) and another is WebControl Project (WebControlLibrary1). The first project includes 'Default.aspx' while the second includes 'ClientScriptResourceLabel.cs'. And we have a js file called 'script_include.js'.
Step1. In the property window of 'script_include.js'. Assign the Build Action attribute with 'Embedded Resource'.
Step2. Add the following code in CilentScriptResourceLabel.cs.
[assembly: WebResource("script_include.js", "application/x-javascript")]
namespace WebControlLibrary1
{
...
}Step3. Until now, We'll see WebControlLibrary1.script_include.js in the resource folder of WebControlLibrary but actually we want the js file attached to the resource folder without the namespace. So you can open WebControlLibrary1.csproj to make the <RootNameSpace> node to be empty.(Only supported in VS2005 Beta2)
Step4. Finnaly, Invoke the resource in cs file.
public class ClientScriptResourceLabel : WebControl
{
protected override void OnPreRender(EventArgs e)
{
if (this.Page != null)
{
ClientScriptManager manager1 = this.Page.ClientScript;
manager1.RegisterClientScriptResource(typeof(ClientScriptResourceLabel), "script_include.js");
}
base.OnPreRender(e);
}
}
Thanks.