RadBinaryImage as CSS background-image?

1 Answer 46 Views
BinaryImage
Phil
Top achievements
Rank 1
Phil asked on 01 Jun 2022, 01:25 PM

Is there a recommended way to use the RadBinaryImage control to serve an image via CSS?

Ideally, I would like to replace a line like this:

background-image: url("mybackground.gif");

with something like this:

background-image: url("<%=  RadBinaryImage1.UrlTheBrowserRequests %>");
<telerik:RadBinaryImage ID="RadBinaryImage1" runat="server"  />

...but as far as I can tell, the serving url not exposed. Is the url is deterministic enough to recreate?

I'm open to alternatives, too. The best I've come up with so far is styling the image as a relatively positioned layer, but there are significant complexities and limitations to that approach, and any explicit sizing plays poorly with the serverside size that get rendered by the control.

Thanks,

Phil

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter Milchev
Telerik team
answered on 06 Jun 2022, 01:01 PM

Hello Phil,

You can check out the KB we recently created related to the BinaryImage:

There you can see the URL is actually obtained this way: 

binaryimage.ResolveClientUrl(binaryimage.ImageUrl)

That means you should be able to use the style rule below as long as the style is defined in the web form and not in an external CSS file:

background-image: url("<%=  RadBinaryImage1.ResolveClientUrl(RadBinaryImage1.ImageUrl)%>");

Regards,
Peter Milchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
BinaryImage
Asked by
Phil
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or