我正在尝试将用户登录详细信息写入数据库。 当我点击提交按钮我得到一个NullReferenceException。 有4个文本框 用户名,电子邮件,密码和ConfirmPassword。ASP.NET NullReferenceException
protected void Button1_Click(object sender, EventArgs e)
{
if ((RegisterUserWizardStep.FindControl("Password") as TextBox).Text == (RegisterUserWizardStep.FindControl("ConfirmPassword") as TextBox).Text)
{
//call the method to execute insert to the database
ExecuteInsert((RegisterUserWizardStep.FindControl("UserName") as TextBox).Text,
(RegisterUserWizardStep.FindControl("Email") as TextBox).Text,
(RegisterUserWizardStep.FindControl("Password") as TextBox).Text);
Response.Write("Record was successfully added!");
ClearControls(Page);
}
else
{
Response.Write("Password did not match");
(RegisterUserWizardStep.FindControl("Password") as TextBox).Focus();
}
}
谢谢。
哪条线发生异常? – 2012-02-24 12:09:21
而当你打破它正在使用的值为空的异常?回答这些问题,你几乎解决了你的问题。 ;-) – Chris 2012-02-24 12:11:01
另外,只是为了检查。在你的描述中你说过你有一个'用户名'文本框。代码正在寻找'RegisterUserWizardStep.FindControl(“UserName”)'。这是一个错字吗? – 2012-02-24 12:11:13