[英]Use a variable derived from Javascript into an ASP tag
I'm having difficulty in using a variable derived from Javascript into an ASP tag . 我在使用从Javascript派生的变量到ASP标记中遇到困难。
<script language="javascript">
if (arg)
{
var text_box_to_fill = arg.sendValue_Code;
document.getElementById( document.getElementById("<%= "+text_box_to_fill+".clientID %>").value = selected_libelle_value;
}
</script>
Any suggestions? 有什么建议么?
Not sure why there are duplicate "document.getElementById" code references, but you can only go from server to client in this fashion. 不确定为什么会有重复的“ document.getElementById”代码引用,但是您只能以这种方式从服务器到客户端。 So it would be:
因此它将是:
<script language="javascript">
if (arg)
{
var text_box_to_fill = arg.sendValue_Code;
document.getElementById("<%= text_box_to_fill.ClientID %>").value = selected_libelle_value;
}
</script>
EDIT: Note that you have to have the script in the same page or control as the origin of "text_box_to_fill". 编辑:请注意,您必须将脚本与“ text_box_to_fill”的来源位于同一页面或控件中。 If you have this script in a page, and the textbox is in the user control, that won't work.
如果您在页面中有此脚本,并且文本框位于用户控件中,则该文本框将不起作用。
text_box_to_fill
is defined client side in the browser, whereas the <% %> tags are evaluated on the server. text_box_to_fill
是在浏览器中定义的客户端,而<%%>标记在服务器上评估。 It's not possible to reference javascript variables from the server code. 无法从服务器代码中引用javascript变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.