无法在javascript中获取asp.net标签的价值 [英] Uneable to get asp.net label's value in javascript

查看:74
本文介绍了无法在javascript中获取asp.net标签的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

  document  .getElementById(' <%= myID.ClientID%>')。value; 



我能够检索asp:TextBox控件的值,但不能检索asp:Label控件的值。对于Label控件,我总是得到

无法获取未定义或空引用的属性值



这个问题有什么暗示吗?谢谢。



我的尝试:



多次尝试标签控件但不成功。

解决方案

A < asp:Label> 呈现为< span> < label> 元素。这些元素没有属性。相反,您需要阅读 innerHTML 属性以获取标签文本。



但是,错误消息表明您的标签元素在文档中不存在。您需要查看页面的渲染源,检查传递给 getElementById 的值,并确保文档中有一个带有该ID的元素。

Using

document.getElementById('<%=myID.ClientID%>').value; 


I am able to retrieve the values of asp:TextBox controls but Not the values of asp:Label controls. For the Label controls, I always get

Unable to get property 'value' of undefined or null reference


Any hint for this problem? Thanks.

What I have tried:

Multiple Tries on the Label controls but not successful.

解决方案

A <asp:Label> renders as either a <span> or a <label> element. Those elements don't have a value property. Instead, you would need to read the innerHTML property to get the text of the label.

However, the error message suggests that your label element doesn't exist in the document. You need to view the rendered source of your page, check the value you're passing to getElementById, and make sure there's an element with that ID in the document.


这篇关于无法在javascript中获取asp.net标签的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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