admin管理员组文章数量:1425677
I got an asp:Image in my server-markup like this:
<asp:Image ID="Img1" runat="server"/>
Now, I want to find this img in my javascript, but seem to run into the problem of ASP.Net obfuscating my names. The client-markup will look something like this:
<img id="ctl00_Content_Img1"/>
I imagine this is because everything is inside a form-element called 'Content', which is quite normal I guess? :)
Any pointers on how to access this from javascript?
[EDIT] I was thinking if there's an easy way to change my javascript "servertime" to search for the obfuscated id ?
I got an asp:Image in my server-markup like this:
<asp:Image ID="Img1" runat="server"/>
Now, I want to find this img in my javascript, but seem to run into the problem of ASP.Net obfuscating my names. The client-markup will look something like this:
<img id="ctl00_Content_Img1"/>
I imagine this is because everything is inside a form-element called 'Content', which is quite normal I guess? :)
Any pointers on how to access this from javascript?
[EDIT] I was thinking if there's an easy way to change my javascript "servertime" to search for the obfuscated id ?
Share Improve this question edited Aug 3, 2009 at 14:34 cwap asked Aug 3, 2009 at 14:24 cwapcwap 11.3k8 gold badges50 silver badges62 bronze badges4 Answers
Reset to default 4Here you can get a server control's client side id by using it's ClientID property like that :
<script>
var imgID = '<%= Img1.ClientID %>';
var imgObject = document.getElementById(imgID);
</script>
You can obtain a client reference of the Id generated on the server-side with the ClientID property:
var img1 = document.getElementById('<%= Img1.ClientID %>');
Just to put the two previous answers together:
var img = document.getElementById('<%= Img1.ClientID %>');
You want to use the document.getElementById
function.
本文标签: aspnetHow to access aspImage from JavascriptStack Overflow
版权声明:本文标题:asp.net - How to access asp:Image from Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745457114a2659153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论