對於親身體驗,我會生成隨機數字,然後在提交時比較它們的總和,但每次我按下按鈕,隨機數字都在變化,我該如何停止發生這種情況?我考慮過不同的實驗,但無法做到這一點。 這裏是隨機數我的類代碼:如何在ASP.NET中使用我自己的隨機驗證碼?
public class Captcha
{
int num1, num2, total;
public int N1
{
get
{
return num1;
}
}
public int N2
{
get
{
return num2;
}
}
public int Total
{
get
{
return total;
}
}
Random r = new Random();
public Captcha()
{
Random r = new Random();
num1 = r.Next(1, 11) * 10;
num2 = r.Next(1, 11);
total = num1 + num2;
}
}
現在,我用這一個在Page_Load事件是這樣的:
Captcha c = new Captcha();
protected void Page_Load(object sender, EventArgs e)
{
Label2.Text = c.N1.ToString();
Label3.Text = c.N2.ToString();
}
我怎樣才能實現這個呢?
謝謝。
您可以發佈您點擊按鈕的代碼? – samar
按鈕代碼正在做很多事情,但我使用captcha比較,所以它就像IF(TextBox2.Text.Equals(c.Total.ToString())){......執行其他代碼...} –