Question:
How to embed an image file as an embedded resource in a server control assembly?How to access an image from a server control assembly?
Answer:
First of all, the image file must be an embedded resource. (right-click on the file and set Build Action to Embedded Resource.)
Follow these steps:
- Register a WebResource for the image file in the AssemblyInfo.cs
... [assembly: System.Web.UI.WebResource("myImage.gif", "img/gif")]; ...
- Get the image URL from the ClientScript manager. (in the OnPrerender event)
Image img = new Image(); string imgUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "myImage.gif"); img.ImageUr = imgUrl;
No comments:
Post a Comment