Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to change the imagebutton image on click , for each click image of image button change alternately pls help me?
Posted
Comments
[no name] 14-Mar-12 7:36am    
What have you tried so far?

If you add an imagebutton to a page and open the page in your favorite browser, then using you favorite tool to investigate the DOM elements you will see the ImageButton control is rendered as a html input element of type image with a src attribute. This should give you some hints to start with.
 
Share this answer
 
Hope it will help you
<script language='javascript'>
<!--
function EvImageOverChange(name, direction)
{
switch(direction)
{
case 'in':
name.src = "image/OverImage.gif";
break;
case 'out':
name.src = "image/InitialImage.gif";
break;
}
}
//-->
</script>

in the code behind insert this in the Page load method:

if(!IsPostBack)
{
myImageButton.ImageUrl = "image/InitialImage.gif";
myImageButton.Attributes["OnMouseOver"] =
"javascript:EvImageOverChange(this, 'in');";
myImageButton.Attributes["OnMouseOut"] =
"javascript:EvImageOverChange(this, 'out');";
}
 
Share this answer
 
Comments
[no name] 14-Mar-12 8:13am    
Not a solution to the question. OP wanted click not mouseover.
Sudip Saha 14-Mar-12 8:24am    
Use it myImageButton.Attributes["onclick"] =
"javascript:EvImageOverChange(this, 'in');";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900