Geeks With Blogs
Łukasz Kuryło's blog

I'm not using very ofter a web resources, so every time I need to use it, I'm wasting my time to google how to do it.

To save my time next time, a little example.

Set the Build Action on the js file to Embedded Resource and add few lines in:

AssemblyInfo:

[assembly: System.Web.UI.WebResource("path.to.my.javascript.file.js", "text/javascript")]

 

and in the custom web control:

protected override void OnPreRender(EventArgs e)
        {
            ClientScriptManager cs = this.Page.ClientScript;
            cs.RegisterClientScriptResource(typeof(MyCustomControl), "path.to.my.javascript.file.js");
        }

Thanks to these two lines in the OnPreRender event, the js script is loading from embedded resources into the page by WebResource.axd http handler. More detailed article can be found here.

Posted on Saturday, June 4, 2011 7:16 PM ASP.NET | Back to top


Comments on this post: Embedding a javascript file as a web resource

Comments are closed.
Comments have been closed on this topic.
Copyright © Łukasz Kuryło | Powered by: GeeksWithBlogs.net