如何在转发器控件内单击图像时如何防止页面刷新 [英] how to prevent page getting refresh when i click image inside repeater control

查看:65
本文介绍了如何在转发器控件内单击图像时如何防止页面刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们

我面临一个问题,我有转发器控制,里面我已经显示图像,当我ckick任何图像整页正在刷新



我的代码如下所示..



Dear friends
I am facing one problem i have repeater control and inside that i have displayed images when i ckick any image whole page is getting refresh

my code is as given below..

<asp:Repeater ID="ProductList" runat="server" OnItemCommand="ProductList_ItemCommand">
                   <ItemTemplate>
                       <div style="float: left;">
                           <div style="width: 40px;border:1px solid #cacaca;margin-right:5px">
                               <a href="Product.aspx?id=<%#Eval("ItemId")%>">
        
                          

 <img id="ProductImg" src='<%#Eval("ImagePath")%>' height="40" width="40" style="text-decoration: none;"  önclick="javascript:imageurl();"/>
                                
                            
                        
                    
                


so plase help me as soon as possible

thanks in advance

推荐答案





您可以使用javascript方法限制图像或图像保留列的点击事件。



//在Aspx设计中 - 解决方案1 ​​

Hi,

You can restrict click event for the image or for image holding column using javascript method.

//In Aspx design -- Solution 1
<asp:repeater id="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound" xmlns:asp="#unknown">
            <itemtemplate>
                <table>
                    <tr>
                        <td>
                            <%# DataBinder.Eval(Container.DataItem, "ID")%>
                        </td>
                        <td>
                            <img id="img" src="  <%# DataBinder.Eval(Container.DataItem, "FilePath")%>" alt="search" onclick="return false" />
                        </td>
                    </tr>
                </table>
            </itemtemplate>
        </asp:repeater>







//代码落后 - 解决方案2
ItemDataBound中的
事件,找到图像并添加onclick属性




//in code behind -- Solution 2
in ItemDataBound Event, Find the image and add the onclick Attribute

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  {
     Image img = (Image)e.Item.FindControl("img");
     if (img != null)
       img.Attributes.Add("onclick", "return false");
   }
}





希望有所帮助。



Hope it helps.


这篇关于如何在转发器控件内单击图像时如何防止页面刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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