通过单击两个来更改2个ImageButton. [英] Change 2 ImageButtons by click on both.
本文介绍了通过单击两个来更改2个ImageButton.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改2个ImageButtons CommandName和ImageUrl
就像当我单击一个ImageButton之后它们改变了位置一样
然后单击另一个Imagebutton?
这是我尝试过的方法,但仅更改了第二张图像
How can I change 2 ImageButtons CommandName and ImageUrl
as if they changed their places after I click one ImageButton
and then I click another Imagebutton?
Here is what I tried but it changes only the second image
protected void ImageButton_Click(object sender, ImageClickEventArgs e)
{
ImageButton img = (ImageButton)sender;
if (ClickedImageButton == null)
ClickedImageButton = img;
else
{
string changeURL = ClickedImageButton.ImageUrl;
ClickedImageButton.ImageUrl = img.ImageUrl;
img.ImageUrl = changeURL;
}
}
(如何通过其ID更改ImageButton属性也将很好.)
(How to change ImageButton properties by it''s ID will be good as well.)
推荐答案
在下面的代码中尝试使用两个图像按钮,其ID为imgButton1和imgButton2:-
Try below code here i use two image button which id is imgButton1 and imgButton2:-
protected void ImageButton_Click(object sender, ImageClickEventArgs e)
{
ImageButton img = (ImageButton)sender;
if (img.ID == "ImgButton1")
imgButton2.ImageUrl= img.ImageUrl;
else
{
imgButton1.ImageUrl=img.ImageUrl;
}
}
甚至在图像按钮中使用Command的另一种方式是使用设置命令名称为imgButton1&的命令. imgButton2分别:-
another way Command even in image button is use where set command name is imgButton1 & imgButton2 respectively:-
protected void ImageButton_Command(object sender, CommandEventArgs e)
{
ImageButton img = (ImageButton)sender;
if (e.CommandName == "ImgButton1")
imgButton2.ImageUrl= img.ImageUrl;
else
{
imgButton1.ImageUrl=img.ImageUrl;
}
}
这篇关于通过单击两个来更改2个ImageButton.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文