This is a migrated thread and some comments may be shown as answers.

Binding Image URL

3 Answers 221 Views
ImageButton
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 21 May 2018, 09:47 PM

     Hi.  I am trying to convert an asp ImageButton to a RadImageButton because there are some useful features that would make my life a bit easier.  However, the binding for the image URL won't work - at least the way I am doing it.

So this works (both are in the same ListView):

<asp:ImageButton ID="im" runat="server" ImageUrl='<%# Eval("ImgUrl") %>'  /> 

 

But this:

<telerik:RadImageButton runat="server" ID="itemImageButton" ' >
     <Image Url='<%# Eval("ImgUrl") %>' />
 </telerik:RadImageButton>  

 

gives me an error something like Telerik.Web.UI.ButtonBase.ButtonImage does not have a DataBinding event.  

Is it possible to do this with the RadImageButton?

3 Answers, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 24 May 2018, 03:40 PM
HI Brian,

RadImageButton is based on the RadButton control and (as stated in the thrown error message) it does not have a DataBinding event neither DataBind method. This is why, unfortunately, it is not possible to use Eval expressions for RadImageButton's properties.

Regards,
Vessy
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Brian
Top achievements
Rank 1
answered on 25 May 2018, 12:59 PM

Hi Vessy and thank you for your reply.  However, it is not completely accurate.  There are two ways to achieve what I needed.  The first (and more difficult by far) is to set up the image in the data bound event of the parent data container (ListView/RadListView in my case).  The second is what I was looking for.  I waited about a day for an answer here and then posted the same question to Stack Overflow.  Someone there was able to give a solution.  The control itself is bindable, but properties added as child elements apparently are not.  The below markup works for my purposes:

 

<telerik:RadImageButton runat="server" ID="itemImageButton" Image-Url='<%# Eval( "ImgUrl" ) %>' />

 

For some reason the attribute in question does not show up in Intellisense, but the image does show up as intended.

I would also like to mention that data binding is a huge part of business class web programming.  The easier it is to do things like this, the more likely someone is to choose your toolkit over another.  I know things in the MS world is moving toward MVC, but it will be a long time before the event based postback model is eliminated.  I would strongly recommend that your team at least consider going through these controls to find a way to make them fully compatible with data binding.  In this case, just having the attribute show up in Intellisense would have kept me from having an issue.

Thanks again!

0
Vessy
Telerik team
answered on 28 May 2018, 03:06 PM
Hi Brian,

Indeed you are correct - even though RadImageButton does not have its own DataBinding event, it can be configured as such if placed inside a boundable container like RadListview. As for the found by you Image-Url property binding - this kind of binding is not an official functionality of the button and this is why we cannot suggest it as such. Still, if it is bringing the target result and there are no any side effects of using it in your project, I cannot think of a reason not to use it :)

Thank you for sharing it with the other developers in our community as well - I hope that this approach will be useful for some other clients.

Regards,
Vessy
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ImageButton
Asked by
Brian
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Brian
Top achievements
Rank 1
Share this question
or