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

Change background image on client

4 Answers 187 Views
Button
This is a migrated thread and some comments may be shown as answers.
Casper
Top achievements
Rank 1
Casper asked on 11 Dec 2012, 04:03 PM
Hello

I'm trying to change the background image of an RadButton with javascript:

<telerik:RadButton runat="server" Width="85px" Height="33px" ID="btnSup"">
                <Image IsBackgroundImage="True" ImageUrl="/Images/Buttons/test.png"></Image>
</telerik:RadButton>

But I can't figure out how to do this? I have looked in the documentation here http://www.telerik.com/help/aspnet-ajax/button-client-side-basics.html but did not find anything.

Any suggestions?

-Casper

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Dec 2012, 05:36 AM
Hi Casper,

Try the following code snippet to achieve your scenario.

JS:
<script type="text/javascript">
    function OnClientLoad(sender, args) {
        var imageData = sender.get_imageData();
        sender._setBackgroundImage(sender.get_element(), "image.jpg");
    }
</script>

Hope this helps.

Regards,
Princy.
0
Casper
Top achievements
Rank 1
answered on 19 Dec 2012, 07:24 PM

Hi Princy

Sorry about the slow response.

Your solution almost works.
When I click the button, my click event change the buttons background (like in your example) and it works, but when I move the cursor away/over the button it change back to the old image.

0
Accepted
Slav
Telerik team
answered on 21 Dec 2012, 04:31 PM
Hi Casper,

Adding the code, marked in the following sample, should help you persist the changed RadButton background image:
<script type="text/javascript">
    function OnClientLoad(sender, args) {
        var imageData = sender.get_imageData();
        sender._setBackgroundImage(sender.get_element(), "image.jpg");
 
        var imageData = { hoveredImageUrl: "image.jpg", imageUrl: "image.jpg" };
        sender.set_imageData(imageData);
    }
</script>

Greetings,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Casper
Top achievements
Rank 1
answered on 26 Dec 2012, 07:14 PM
Thank you very much, that worked.
Tags
Button
Asked by
Casper
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Casper
Top achievements
Rank 1
Slav
Telerik team
Share this question
or