Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir,

<asp:ImageButton ID="imgF1" runat="server" alt="A1" ImageUrl="~/Images/red_white.png"/>

this is my imageButton whene click on this imageButton i want to change there image.
I have 2 images, 1st is red_white.png and 2nd is white.png
plz help...
Posted
Updated 21-Mar-14 2:28am
v2

You can use the following code to change the image on every click:

C#
<asp:ImageButton ID="imgF1" runat="server" alt="A1" ImageUrl="~/Images/red_white.png" OnClientClick="if (this.src.indexOf('red_white.png') != -1) this.src='images/white.png'; else this.src='images/red_white.png';return false;" />
 
Share this answer
 
v2
You can use the click event and change the ImageUrl property in it.

Or you can use client side event[^] to solve your problem.

If you would like to change the value what depends on the actual value, you only have to check it first in the click event. For example:
C#
imgF1.ImageUrl = imgF1.ImageUrl == "red_white.png" ? "white.png" : "red_white.png";

I think that's it.
 
Share this answer
 
v3
Comments
Rajkumar_007 21-Mar-14 8:28am    
But i want to do multiple selection of imageButton....
norbitrial 21-Mar-14 8:32am    
What do you mean by that? If you would like to change the value what depends on the actual value, you only have to check it first in the click event. For example: imgF1.ImageUrl == "red_white.png" ? "white.png" : "red_white.png ";
I think that's it.
JoCodes 21-Mar-14 9:12am    
Norbitrial , that seems to be the Answer for me , add it in your solution
norbitrial 21-Mar-14 9:29am    
I've improved my solution.
Instead of this You can use

Toggle button extender in Ajax


or else image click event
C#
protected void btnview_Click(object sender, ImageClickEventArgs e)
   {

            btnview.ImageUrl = "~/Images/export.jpg";
}
 
Share this answer
 

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