views:

231

answers:

2

Hi all,

I'm practicing to use embedded resource in ASP.Net. I wrote a javascript file, put it into a C# class library and change It's Build Action Property to Embedded Resource. In my web project, I added reference to the that class library. I want to use that javascript file in my web pages but i don't know how? please help me

Thanks

A: 

Please, take a look here: Embedding Resources in ASP.NET 2.0 Assemblies

Rubens Farias
I'm reading it but perhalp it doesn't help me very much
Linh
A: 

My problem was resolved. Anybody can accomplish as following steps: - Add a class library to your solution - Add the resource files which you want to embed - Register your resource in AssemblyInfo.cs

[assembly: System.Web.UI.WebResource("A.B.C", "D")]

with: A is your class library name B is the folder's name which contain your resource file C is the resource files'name D is the content type of your resource ("text/javascript" or another)

  • In the code behind file of the asp.net page you include the resource:

string scriptLocation = Page.ClientScript.GetWebResourceUrl(typeof(the empty class' name which added before), "A.B.C"); Page.ClientScript.RegisterClientScriptInclude("A.B.C", scriptLocation);

  • test what you have done
Linh