Programmatically adding Javascript File to User Control in .net

后端 未结 8 1967
不知归路
不知归路 2020-12-24 08:08

How do you add Javascript file programmatically to the user control?

I want the user control to be a complete package - ie I don\'t want to have to add javascript th

8条回答
  •  悲哀的现实
    2020-12-24 09:01

    You can register client script includes using the ClientScriptManager. Page is accessible through the Control.Page property.

    Page.ClientScript.RegisterClientScriptInclude (
      typeof ( MyControl ), "includeme.js", "js/includeme.js"  );
    

    EDIT: Sorry, for a total "complete package", its possible using scripts as Embedded Resources, and aquire dynamic URL's through the WebResource.axd handler. If this is not considered totally complete, then i guess it could be put in App_LocalResources, but it never gonna be just one file, unless the code and script is inline.

提交回复
热议问题