单击imageButton时如何更改图像按钮的图像? [英] how to change image of imagebutton when click on imageButton?

查看:77
本文介绍了单击imageButton时如何更改图像按钮的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



< asp:ImageButton ID =imgF1runat =serveralt =A1ImageUrl =〜/ Images / red_white .png/>



这是我的imageButton点击这个图片按钮我想改变那里的图像。

我有2张图片,1st是red_white.png,2nd是white.png

plz help ...

解决方案

您可以使用以下代码进行更改每次点击时的图像:



< 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';否则这个。 src ='images / red_white.png';返回false; /> 


您可以使用click事件并更改ImageUrl属性在它。



或者你可以使用客户端事件 [ ^ ]来解决您的问题。



如果您想要更改取决于实际值的值,您只需在click事件中首先检查它。例如:

 imgF1.ImageUrl = imgF1.ImageUrl ==   red_white.png  white.png < span class =code-string> red_white.png; 



我认为就是这样。


取而代之您可以使用



切换按钮扩展器在阿贾克斯





或图像点击事件

  protected   void  btnview_Click( object  sender, ImageClickEventArgs e)
{

btnview.ImageUrl = 〜/ Images / export .JPG;
}


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

解决方案

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

<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;" />


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:

imgF1.ImageUrl = imgF1.ImageUrl == "red_white.png" ? "white.png" : "red_white.png";


I think that's it.


Instead of this You can use

Toggle button extender in Ajax


or else image click event

protected void btnview_Click(object sender, ImageClickEventArgs e)
   {

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


这篇关于单击imageButton时如何更改图像按钮的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆