使用此代码时我遇到错误? [英] i am facing error when i use this code?
本文介绍了使用此代码时我遇到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个运行时代码来验证...
但是无论我提供的代码是否正确,它都显示错误....
为什么?
i am created a run time code to validate...
but its showing wrong whether i gave correct code....
why?
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
long i = 1;
foreach (byte b in Guid.NewGuid().ToByteArray())
{
i *= ((int)b + 1);
}
TextBox1.Text = string.Format("{0:x}", i - DateTime.Now.Ticks);
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == TextBox2.Text)
{
Response.Write("Hai");
}
else
{
Response.Write("wrong");
}
}
}
推荐答案
您需要在Page_Load
代码中检查IsPostBack
:
You need to check forIsPostBack
in yourPage_Load
code:
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
long i = 1;
foreach (byte b in Guid.NewGuid().ToByteArray())
{
i *= ((int)b + 1);
}
TextBox1.Text = string.Format("{0:x}", i - DateTime.Now.Ticks);
}
}
这篇关于使用此代码时我遇到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文