Image in ImageButton in CompositeControl RRS feed

  • Question

  • User304384516 posted

    I have an ImageButton in a CompositeControl. In CreateChildControls(), I want to set the image. The image is a png file that I have made an Embedded Resource. In code-behind, I can get the image from resources. But how do I get a url for the ImageUrl property of the ImageButton?


    Tuesday, September 6, 2011 3:08 PM


  • User304384516 posted

    Further looking found the answer.

    1. Set Build Action for the image file to Embedded Resource.
    2. Add '[assembly: WebResourceAttribute("MyNameSpace.MyImage.png", "image/png")]' to AssemblyInfo.cs.
    3. Use 'Page.ClientScript.GetWebResourceUrl(typeof(MyNameSpace.MyControl), "MyNameSpace.MyImage.png")' to get a suitable value for ImageUrl.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2011 4:29 PM