'Input string never equals the random string
It should return "success", but it always returns the answer of "fail".
protected void Button3_Click(object sender, EventArgs e)
{
Random rnd = new Random();
randomNumber = (rnd.Next(100000, 999999)).ToString();
Label1.Text = randomNumber;
}
protected void Button2_Click(object sender, EventArgs e)
{
if (TextBox1.Text != randomNumber)
{
Label1.Text = "fail";
}
else
{
Label1.Text = "success";
}
}
Here is the HTML part.
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="Button" OnClick="Button3_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
