views:

84

answers:

1

How can I use an image or icon resource from global resource file in an asp:Image control to set the ImageUrl attribute?

+1  A: 

In code:

ClientScriptManager cs = Page.ClientScript;
myImage.ImageUrl= cs.GetWebResourceUrl(type, "resource name");

In the markup:

<asp:Image 
     ImageUrl="<%= Page.ClientScript.GetWebResourceUrl(typeof(MyClass), 
     "resource name") %>" 
 />

See the documentation for ClientScriptManager.GetWebResourceUrl for more info.

womp
I used the code in the markup and I got this error Server tags cannot contain <% ... %> constructs.
Use the "In code" example instead. Put it in the Page_Load event.
awe