简体   繁体   English

有没有办法在代码后面访问javascript变量?

[英]is there a way to access javascript variable in code behind?

here's my code 这是我的代码

function qtyblur() {
    var textgettaxbaseid = document.getElementById("txttaxbase");
    var textgettaxbasevalue = textgettaxbaseid.value;
    var taxbase = parseFloat(textgetsubtotalid.value / 1.12).toFixed(2);
    textgettaxbaseid.value = taxbase;
}

I want to access my variables here and use it in my code behind. 我想在这里访问我的变量并在后面的代码中使用它。 I am really new to this so bear with me. 我真的很新,所以请耐心等待。

To access what you have in client side (javascript) in code bahind you need to send a call to server. 要在代码bahind中访问客户端(javascript)中的内容,您需要向服务器发送调用。 You call post the form or send an ajax call on server. 您可以在服务器上发布表单或发送ajax调用。

Usually we put the javascript variable values in some hidden field and get the hidden field in code behind and extract the values of javascript. 通常我们将javascript变量值放在一些隐藏字段中,并在后面的代码中获取隐藏字段并提取javascript的值。

no you cannot. 你不能。 Instead, use a Hidden Field in you javascript function, assign a variable's value to it and use the Hidden Field in your code behind. 相反,在javascript函数中使用隐藏字段,为其指定变量值并在后面的代码中使用隐藏字段。

在代码隐藏中使用Web方法,并使用jquery和json将javascript变量传递给Web方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM