我有以下代码:
protected void Button1_Click(object sender, EventArgs e)
{
count1++;
}
我希望每次有人点击按钮时计数器count1都会增加。然而,到目前为止它只计算第一次点击,而不是任何其他跟随,所以它总是停留在1.外面,我已经声明它并将其初始值设置为0.问题出在哪里? (我使用visual studio 2015)
编辑:这是整个代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Statistics : System.Web.UI.Page
{
int count1 = 0, count2 = 0;
string minima = "Καλησπέρα";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TextBox1.Text = minima;
Label1.Text = "Αυτή την στιγμή χρησιμοποιούν τον ιστότοπο " + Convert.ToString(Application["UserCount"]) + " χρήστες";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = TextBox1.Text;
count1++;
Label2.Text = "Κλικ από προηγούμενους χρήστες: " + Convert.ToString(count1);
Label3.Text = "Τρέχοντα κλικ: " + Convert.ToString(count1 + count2);
}
}
(是的,我知道count2在任何时候都没有改变它的值,代码仍在进行中,因为它存在于另一个原因所以让我们暂时忽略它)
答案 0 :(得分:-1)
您的计数器正在重置每个回发 试试这个
String string = "{\"success\":1,\"data\":{\"html\":\"<div class=\\\"inner\\\">\\n <span class=\\\"title js-title-eligible\\\">Upgrade available<\\/span>\\n <span class=\\\"title js-title-warning\\\"><strong>WARNING :<\\/strong> You don\\u2019t own a <span class=\\\"js-from-ship\\\"><\\/span><\\/span>\\n <p class=\\\"explain js-title-eligible\\\">Buy this upgrade and it will be applicable to your <span class=\\\"js-from-ship\\\"><\\/span> from the My Hangar section.<\\/p>\\n <p class=\\\"explain js-title-warning\\\">You can buy this upgrade but it will only be applicable on a <span class=\\\"js-from-ship\\\"><\\/span>.<\\/p>\\n\\n <div class=\\\"price\\\"><strong class=\\\"final-price\\\">\\u20ac5<span class='super'>.41 <span class='currency'>EUR<\\/span><\\/span><\\/strong><div class=\\\"taxes js-taxes\\\">\\n <div class=\\\"taxes-details trans-02s\\\">\\n <div class=\\\"arrow\\\"><\\/div>\\n Tax Included: <br \\/>\\n <ul>\\n <li>VAT 19%<\\/li>\\n <\\/ul>\\n <\\/div>\\n<\\/div><\\/div>\\n\\n\\n <div>\\n <a href=\\\"\\/pledge\\/Upgrades\\/Mustang-Alpha-To-Aurora-LN-Upgrade\\\" class=\\\"add-to-cart holosmallbtn trans-03s js-add-to-cart-ship ty-js-add-to-cart\\\" data-sku=\"1086\\\">\\n <span class=\\\"holosmallbtn-top abs-overlay trans-02s\\\">BUY NOW<\\/span>\\n <span class=\\\"holosmallbtn-bottom abs-overlay trans-02s\\\"><\\/span>\\n <\\/a>\\n <a href=\\\"\\/pledge\\/Upgrades\\/Mustang-Alpha-To-Aurora-LN-Upgrade\\\" class=\\\"more-details\\\">View more details<\\/a>\\n <\\/div>\\n \\n <p class=\\\"explain info\\\">\\n Upgrades that you buy can be found in your <a href=\\\"\\/account\\/pledges\\\">Hangar section<\\/a>.<br \\/>\\n Click \\\"Apply Upgrade\\\" inside the Upgrade Pledge to pick where you want to apply it.\\n <\\/p>\\n <\\/div>\\n\\n\\n\\n\"},\"code\":\"OK\",\"msg\":\"OK\"}";
String pattern="(?<=data-sku=)([\\\\]*\")(\\d+)";
Pattern p = Pattern.compile(pattern);
Matcher matcher = p.matcher(string);
while (matcher.find()) {
System.out.print("Start index: " + matcher.start());
System.out.println(" End index: " + matcher.end() + " ");
System.out.println("number="+matcher.group(2));
}