如何访问从code JavaScript变量在asp.net背后 [英] How to access a JavaScript variable from code behind in asp.net

查看:105
本文介绍了如何访问从code JavaScript变量在asp.net背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是JavaScript和它有以下code:

i am using a JavaScript and it have the below code:

<script type="text/javascript">
var count = 0;

jQuery('td').click(function () {
    if ($(this).hasClass('process')) {
       count = count+100;
       alert('count');
}
});
</script>

所以如果点击的价值由100加入我检查使用警报,现在如何访问VAR 计数在我的code-背后

推荐答案

您将需要计数变量存储在服务器端控制,以做到这一点。

You will need to store the count variable on a server-side control in order to do this.

示例:

<script type="text/javascript">
    var count = 0;

    jQuery('td').click(function () {
        if ($(this).hasClass('process')) {
           count = count + 100;
           alert(count);
           // Store the value in the control
           $('#<%= example.ClientID %>').val(count);
        }
     });
</script>

<asp:HiddenField ID="example" runat="server" />

然后,在你的code-后面简单的使用:

Then, in your code-behind simply use:

int value;
if (Int32.TryParse(example.Value, out value))
{
     // Do something with your value here
}

这篇关于如何访问从code JavaScript变量在asp.net背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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