在gridview内的转发器内获取图像控制的客户端ID

时间:2018-04-17 15:22:53

标签: javascript

如何获取图像控制的客户端ID

<asp:GridView ID="gv" OnRowDataBound="GetItems" runat="server" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Font-Names="tahoma" Font-Size="8pt" AutoGenerateColumns="False" Height="154px" Width="929px">
    <Columns>
          <asp:TemplateField HeaderText="pic">
            <ItemTemplate>
                <asp:Repeater ID="pictures" runat="server">
                    <ItemTemplate> 
                        <asp:Image ID="Image1" runat="server" height="120" width="90"  ImageUrl='<%# Eval("ImageUrl") %>' onclick="DisplayNewImageInWidnow();" />  
                    </ItemTemplate>
                </asp:Repeater>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

我使用此代码,但它不起作用

function DisplayNewImageInWidnow()
{
    var img = document.getElementById('<%=gv.FindControl("pictures").FindControl("Image1").ClientID %>').src

1 个答案:

答案 0 :(得分:0)

OnClientClick="return DisplayNewImageInWidnow();"

或阻止服务器端运行

OnClientClick="DisplayNewImageInWidnow();return false;"

然后

function DisplayNewImageInWidnow(obj)
{
    var imgId = obj.id;
}