本文介绍了改变图像URL时,点击图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个图像按钮他们不得不默认图像的URL,我试图改变图像的URL时的任何图像按钮,用户点击默认检索当用户点击到其他图像按钮尝试这样做,但我没有。
<&ASPX GT;
< DIV CLASS =hom_but_sa hom_but_saR>
< ASP:ImageButton的ID =BTNPromotion的ImageUrl =图片/家庭bu_npro.jpg
=服务器WIDTH =134HEIGHT =34边界=0
的OnClick =BTNPromotion_Click/>
< / DIV>
< DIV CLASS =hom_but_a hom_but_sbR>
< ASP:ImageButton的ID =BTNNewProduct的ImageUrl =图片/家庭bu_pro.jpg
=服务器WIDTH =134HEIGHT =34边界=0
的OnClick =BTNNewProduct_Click/>
< / DIV>
< DIV CLASS =hom_but_a>
< ASP:ImageButton的ID =BTNEvent=服务器的ImageUrl =图片/家庭bu_news.jpg
WIDTH =134HEIGHT =34边界=0的OnClick =BTNEvent_Click/>
< / DIV>
< / DIV>< CS>
保护无效BTNEvent_Click(对象发件人,ImageClickEventArgs E)
{
BTNEvent.ImageUrl =图像/家庭bu_news.jpg
}
保护无效BTNNewProduct_Click(对象发件人,ImageClickEventArgs E)
{
BTNNewProduct.ImageUrl =图像/家庭bu_pro_r.jpg
}
保护无效BTNPromotion_Click(对象发件人,ImageClickEventArgs E)
{
BTNPromotion.ImageUrl =图像/家庭bu_npro_r.jpg
}
解决方案
按我的意见,我不知道你实际的问题是什么,但也许你需要某种像这样的切换呢?
保护无效BTNEvent_Click(对象发件人,ImageClickEventArgs E)
{
BTNEvent.ImageUrl =图像/家庭bu_news_r.jpg
BTNNewProduct.ImageUrl =图像/家庭bu_pro.jpg
BTNPromotion.ImageUrl =图像/家庭bu_npro.jpg
}
保护无效BTNNewProduct_Click(对象发件人,ImageClickEventArgs E)
{
BTNEvent.ImageUrl =图像/家庭bu_news.jpg
BTNNewProduct.ImageUrl =图像/家庭bu_pro_r.jpg
BTNPromotion.ImageUrl =图像/家庭bu_npro.jpg}
保护无效BTNPromotion_Click(对象发件人,ImageClickEventArgs E)
{
BTNEvent.ImageUrl =图像/家庭bu_news.jpg
BTNNewProduct.ImageUrl =图像/家庭bu_pro.jpg
BTNPromotion.ImageUrl =图像/家庭bu_npro_r.jpg
}
一个更清洁的方法是只需要点击事件由一个事件连接到所有的的ImageButton
的OnClick
:
的OnClick =BTN_Click
然后实施点击
这样的:
保护无效BTN_Click(对象发件人,ImageClickEventArgs E)
{
的ImageButton BTN =(的ImageButton)(寄件人);
BTNEvent.ImageUrl =(btn.ID.Equals(BTNEvent))?
图像/家庭bu_news_r.jpg:图像/家庭bu_news.jpg
BTNNewProduct.ImageUrl =(btn.ID.Equals(BTNNewProduct))?
图像/家庭bu_pro_r.jpg:图像/家庭bu_pro.jpg
BTNPromotion.ImageUrl =(btn.ID.Equals(BTNPromotion))?
图像/家庭bu_npro_r.jpg:图像/家庭bu_npro.jpg
}
I had three image buttons they had default image url and I tried to change image url when user click on any image button and the default retrieve when user click to other image button tried to do that but I did not
<aspx>
<div class="hom_but_sa hom_but_saR">
<asp:ImageButton ID="BTNPromotion" ImageUrl="images/home-bu_npro.jpg"
runat="server" Width="134" Height="34" border="0"
OnClick="BTNPromotion_Click" />
</div>
<div class="hom_but_a hom_but_sbR">
<asp:ImageButton ID="BTNNewProduct" ImageUrl="images/home-bu_pro.jpg"
runat="server" Width="134" Height="34" border="0"
OnClick="BTNNewProduct_Click" />
</div>
<div class="hom_but_a">
<asp:ImageButton ID="BTNEvent" runat="server" ImageUrl="images/home-bu_news.jpg"
Width="134" Height="34" border="0" OnClick="BTNEvent_Click" />
</div>
</div>
<cs>
protected void BTNEvent_Click(object sender, ImageClickEventArgs e)
{
BTNEvent.ImageUrl = "images/home-bu_news.jpg";
}
protected void BTNNewProduct_Click(object sender, ImageClickEventArgs e)
{
BTNNewProduct.ImageUrl = "images/home-bu_pro_r.jpg";
}
protected void BTNPromotion_Click(object sender, ImageClickEventArgs e)
{
BTNPromotion.ImageUrl = "images/home-bu_npro_r.jpg";
}
解决方案
As per my comments I am not sure what you actual problem is but maybe you want some sort of toggle like this?
protected void BTNEvent_Click(object sender, ImageClickEventArgs e)
{
BTNEvent.ImageUrl = "images/home-bu_news_r.jpg";
BTNNewProduct.ImageUrl = "images/home-bu_pro.jpg";
BTNPromotion.ImageUrl = "images/home-bu_npro.jpg";
}
protected void BTNNewProduct_Click(object sender, ImageClickEventArgs e)
{
BTNEvent.ImageUrl = "images/home-bu_news.jpg";
BTNNewProduct.ImageUrl = "images/home-bu_pro_r.jpg";
BTNPromotion.ImageUrl = "images/home-bu_npro.jpg";
}
protected void BTNPromotion_Click(object sender, ImageClickEventArgs e)
{
BTNEvent.ImageUrl = "images/home-bu_news.jpg";
BTNNewProduct.ImageUrl = "images/home-bu_pro.jpg";
BTNPromotion.ImageUrl = "images/home-bu_npro_r.jpg";
}
A cleaner way would be to just have one click event handle it by attaching one event to all the ImageButton
OnClick
:
OnClick="BTN_Click"
Then implement the Click
like:
protected void BTN_Click(object sender, ImageClickEventArgs e)
{
ImageButton btn = (ImageButton)(sender);
BTNEvent.ImageUrl = (btn.ID.Equals("BTNEvent")) ?
"images/home-bu_news_r.jpg" : "images/home-bu_news.jpg";
BTNNewProduct.ImageUrl = (btn.ID.Equals("BTNNewProduct")) ?
"images/home-bu_pro_r.jpg" : "images/home-bu_pro.jpg";
BTNPromotion.ImageUrl = (btn.ID.Equals("BTNPromotion")) ?
"images/home-bu_npro_r.jpg" : "images/home-bu_npro.jpg";
}
这篇关于改变图像URL时,点击图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!