2

How to change Imageurl of imagebutton using javascript?

5 Answers 5

8
document.getElementById("<%= imageButton.ClientId %>").src = "...";
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

2

With jQuery:

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

Comments

2

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...

Comments

1
    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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.