2

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.