user632299
user632299

Reputation: 309

How to change Imageurl of imagebutton using javascript?

How to change Imageurl of imagebutton using javascript?

Upvotes: 2

Views: 25856

Answers (5)

Suresh
Suresh

Reputation: 466

Hi if you try to change image URL on mouse over or any other events, its very simple, try this,

<asp:ImageButton ID="test"  ImageUrl="~/images/Your_old_image" onmouseover="this.src='images/your_new_image';" onmouseout="this.src='images/your_old_image';" runat="server" />

You can use this on onclient event also....

Normally we don't have the event onmouseover and onmouseout on asp:imagebutton.But we can include that...

I hope this will help...

Upvotes: 2

Mahesh KP
Mahesh KP

Reputation: 6446

    function ChangeImage() {

        var img = document.getElementById('<%=ImageButton1.ClientID%>');
        img.src = 'Images/drag.gif';            
        return false;
    }    


    <asp:ImageButton ID="ImageButton1" runat="server" />        
    <asp:Button ID="Button1" runat="server" OnClientClick="return ChangeImage()"
        Text="Button" />

Its worked for me

Upvotes: 1

onof
onof

Reputation: 17367

With jQuery:

$("#<%= imageButton.ClientId %>").attr("src", "...");

Upvotes: 2

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68687

document.getElementById("<%= imageButton.ClientId %>").src = "...";

Upvotes: 8

Nimrod
Nimrod

Reputation: 1346

document.getElementById("id-of-image-button").src = "...";

Upvotes: 2

Related Questions