Search code examples
c#asp.netimagebuttonimageurl

Use of ImageButton without ImageURL to display the image


I need to use the asp control "ImageButton" in order to have access to the properties "OnClick" and "OnClientClick"

The problem is i cannot give any ImageURL since my Image is in Database.

I used this previously :

              <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Image") %>'
                    AutoAdjustImageControlSize="false" Width="90px" Height="110px"  Enabled="true"  AlternateText="pas d'image"/>

But i don't have any Datavalue property in ImageButton control...

How can i manage to do this using ImageButton? thanks in advance


Solution

  • You can use a Generic Handler file and call that as your ImageUrl like:

    <asp:ImageButton ImageUrl='<%# String.Format("Image.ashx?id={0}", eval("ID")) %>' />
    

    Read more on how to do this here:

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=129


    The fact its an ImageButton makes no difference. It's the fact you want to render an image from image data type. I believe generating the image on the fly using a Generic Handler file is the most common way.