保持按钮点击次数跟踪 [英] Keeping track of number of button clicks

查看:165
本文介绍了保持按钮点击次数跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我有一个CAPTCHA图像的页面。

Let us assume that I have a page with a CAPTCHA image.

我想,让用户尝试输入code 3次,否则他是不允许这样做了。

I want to let the user try to enter the code for three times, otherwise he is not allowed to do it anymore.

我如何跟踪次数的确认按钮被点击。 确认按钮,必须执行回发到服务器的每被点击一次。

How can I keep track of the number of times the "Confirm" button has been clicked. The "Confirm" button has to perform a postback to the server every time it is clicked.

使用JavaScript不好,因为,如果用户重新加载网页时,计数器将被设置为零。如何才能做到这一点吗?

Using JavaScript is not good since if the user reloads the page, the counter would be set to zero. How can this be done please?

推荐答案

这应该是pretty直线前进。第一计数器设为零,然后更新其上随后的后背上:

This should be pretty straight forward. First set the counter to zero, and then update it on subsequent post backs:

if (!this.IsPostBack) { Session["RetryCount"] = 1; }
else
{
    int retryCount = (int)Session["RetryCount"];
    if (retryCount == 3) { // do something because it's bad }
    else { retryCount++; Session["RetryCount"] = retryCount; }
}

这篇关于保持按钮点击次数跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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