Welcome on Kweetix Technical Blog

Friday, June 19, 2009

ASP.NET: 3 Steps to embed web resources into dll

If you want to make your own custom control. Yes, custom - not user control. You have something that should work good, everywhere and run from single dll. But how to store images, javascript and other stuff inside this dll? Everything looks fine, but it always cause problems. I decided to write 3 simple steps to embed javascript into your custom control.

Add your JS file to custom control project. Right click on the file - Properties - Build Action - Embedded Resource
Open your AssembyInfo.cs file and add following line

[assembly: System.Web.UI.WebResource("YourNamespace.FileName.js", "application/x-javascript")]

In your custom control OnLoad event add following line:

Page.ClientScript.RegisterClientScriptResource(this.GetType(), "YourNamespace.FileName.js");

That's all!