ASP.NET WebResource behavior in Web User Control (.ascx file)

June 01, 2012

Today very talented colleauge of mine sent out to us very nice catch about requesting resources from .ascx file.

So this is the mail (yes, he said OK to publish it :))

Hi All,

pay attention when requesting resources using embedded resource and WebResource.axd.

Generally you use this:

Page.ClientScript.GetWebResourceUrl(GetType(), "MyNamespace.Folder.resourceName.ext")

But in case you do this in ASCX code behind it won’t work (at least for me :))

To make it working you must pass explicit type to the method:

Page.ClientScript.GetWebResourceUrl(typeof(MyType), "MyNamespace.Folder.resourceName.ext")

Or course do not forget to register handler in .config:

<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="true" />

and resources in .cs file:

[assembly: System.Web.UI.WebResource("MyNamespace.Folder.resourceName.ext ", "image/png")]

I just wanted to share this with you. Btw you can reach author of this here :

http://www.linkedin.com/profile/view?id=122801475&locale=en_US&trk=tyah

Hope this helps.


Profile picture

Written by Dušan Roštár - the "mr edge case" guy
my twitter : rostacik, my linkedin : rostar, drop me an email : here