admin管理员组文章数量:1308623
I am using following code to find control id.
alert(document.getElementById("<%# TextBox1.ClientId %>").value )
but this code is giving error "object required". Please help me.
I am using following code to find control id.
alert(document.getElementById("<%# TextBox1.ClientId %>").value )
but this code is giving error "object required". Please help me.
Share Improve this question asked May 16, 2012 at 12:09 user1369925user1369925 552 gold badges4 silver badges12 bronze badges 1- 1 Do you have a control with that name...? – gdoron Commented May 16, 2012 at 12:10
5 Answers
Reset to default 3You need to use '=', not '#'
alert(document.getElementById("<%= TextBox1.ClientId %>").value );
The "<%#
" symbol is an inline expression used for databinding.
The "<%=
" symbol there is used for display / translation purposes. It basically does a Response.Write
of just the value of the .ClientID
property of your server control.
See this article on inline expressions in asp for more info.
replace # with = in the given statement updated statement is
alert(document.getElementById("<%= TextBox1.ClientId %>").value);
Either use
alert(document.getElementById("<%= TextBox1.ClientId %>").value )
or set ClientIDMode="Static"
for textbox and then
alert(document.getElementById("<%= TextBox1 %>").value )
Also check How to: Access Controls from JavaScript by ID
alert(document.getElementById('Id of control').value )
You can get the exact id of control by view source.
In the context of JavaScript, which is on the client side "<%# TextBox1.ClientId %>"
has no meaning because this will be translated by ASP into to a different ID based on how you configure TextBox1.ClientIDMode
for which you have 4 modes described here Control.ClientIDMode
本文标签: javascriptHow to find a asp control id using java scriptStack Overflow
版权声明:本文标题:javascript - How to find a asp control id using java script? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741864089a2401797.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论