Thursday 26 September 2013





1. Create a JavaScript file and put it in directory under the root project’s directory:
2. Open the properties of the JavaScript file. Under “Build Action” select “Embedded Resource”.
3. In the “AssemblyInfo.cs” add this line:
[assembly: System.Web.UI.WebResource("[Assembly Name].[Folder].[JS file]", "text/javascript")]
For Example, in my project:
[assembly:
System.Web.UI.WebResource("XXX.WebPart.ListViewer.Script.ListViewer.js", "text/javascript")]

4. Add this line in the constractor of your control / web-part:this.PreRender += new EventHandler(MyControl_PreRender);

5. Add these 2 lines in the Pre_Render event of your web-part:string jsLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), "[Assembly Name].[Folder].[JS File]");
Page.ClientScript.RegisterClientScriptInclude("MyScript", jsLocation);

No comments:

Post a Comment