Reputation: 309
How to change Imageurl of imagebutton using javascript?
Upvotes: 2
Views: 25856
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
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
Reputation: 68687
document.getElementById("<%= imageButton.ClientId %>").src = "...";
Upvotes: 8