Monday, September 29, 2008

Embedding Javascript file in custom control

  1. Add javascript file to your project
  2. Set Build Action of this file Embeded Resource
  3. Add the following entry into your AssemblyInfo.cs
    [assembly: WebResource("YourNameSpace.Filename.js", "text/javascript")]
  4. Add following code in your OnInit event

    string webresourceURL = Page.ClientScript.GetWebResourceUrl(this.GetType(), "YourNameSpace.Filename.js");
    this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "cctextbox",webresourceURL);
  5. Please remember YourNameSpace is base name space in your project