使用javascript获取数据列表中的图像控件的Image.ClientID [英] get Image.ClientID of image Control that is inside datalist using javascript

查看:73
本文介绍了使用javascript获取数据列表中的图像控件的Image.ClientID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.我有一个数据列表控件,它显示一个人的详细信息,例如他的照片,姓名..etc.还有一个图像按钮,单击该按钮可显示文件上传控件.在我选择要上传的文件后,图像控件应显示所选的照片.
现在,我已经确定了显示图像的逻辑.当我没有数据列表中的图像时,这工作正常.我面临的问题是我的JavaScript无法识别数据列表中图像的图像ID.以下是我的JavaScript代码和标记代码...

Hello,everyone. I have a datalist control that shows a persons details such as his photo,name..etc. There is also an image button, which when clicked reveals a fileupload control. after i select the file to upload the image control should show the selected photo.
Now, i''ve already worked out the logic for showing the image. This works fine when i don''t have the image inside the datalist. The problem i''m facing is my javascript does not identify the image id of the image that is inside the datalist. Following is my javascript code and the markup code...

function getRandomNumber()
        {
            var randNumber=Math.random(10000);
            return randNumber;
            
        }
        function ClientUploadComplete(sender,args)
        {
            var handlerPage='<%= Page.ResolveClientUrl("~/Handlers/PreviewImageHandler.ashx") %>';
            var queryString='?randomno='+getRandomNumber();
            var src= handlerPage + queryString;
            var clientID='<%= imgMember.ClientID %>';
            document.getElementById(clientID).setAttribute("src",src);
            
        }
// The datalist control
<asp:DataList ID="dtlistEditMembers" runat="server" CssClass="dlistStyle">
               <ItemTemplate>
                   
                <asp:Image ID="imgMember" ImageUrl='<%# "~/Handlers/GetImageHandler.ashx?B_ID=" + Eval("B_ID") %>' AlternateText="No Image" runat="server" />
..............
........
.......
                <div class="EditFields">
                    <asp:Label ID="lblFullName" Text="Name:" runat="server"></asp:Label><asp:TextBox ID="txtFullName" Text='<%# Eval("Full_Name") %>' 
               </ItemTemplate>
            </asp:DataList>



带下划线的控件是我想要其客户端ID的图像控件.当查看页面的源代码时,... asp:image ....会转换为此



The underlined control is the image control whose client id, i want.When viewing the page''s source...the asp:image....is converted to this

<img id="dtlistEditMembers_ctl00_imgMember" src="../../Handlers/GetImageHandler.ashx?B_ID=33" alt="No Image" style="border-width:0px;" />



因此,我该如何编写ClientUploadComplete函数,以便该变量



so, how can i write the ClientUploadComplete function so that the variable

var clientID='<%= imgMember.ClientID %>';

实际上可以识别imgMember控件???

任何帮助将不胜感激.
谢谢,Minghang

actually recognize the imgMember Control???

Any Help would be apreciated.
Thanks, Minghang

推荐答案

替换为行

var clientID =''<%= imgMember.ClientID%>'';



var clientID =
replace below line

var clientID=''<%= imgMember.ClientID %>'';

with

var clientID=


(``#dtlistEditMembers_ctl00_imgMember'');

whichl将返回图像id,这确实可以工作;
(''#dtlistEditMembers_ctl00_imgMember'');

whichl will return image id ,this will really work;


这篇关于使用javascript获取数据列表中的图像控件的Image.ClientID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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