下面是我的简单页面的提交按钮单击的代码。我正在提交一个空表单,但没有显示服务器验证错误消息。我的代码有什么问题?当我点击提交时,页面只是变成空白,没有任何反应。我也无法附加调试器。
当我构建我的网站项目时,它也没有显示任何编译错误。我不知道我做错了什么。
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Need to Validate All Required Fields before redirecting to frmPersonalVerified.aspx
bool blnFormIsValid = true;
DateTime dtEndDate;
DateTime dtStartDate;
// Get Date because we have a value.
dtEndDate = DateTime.Parse(txtEndDate.Text);
// Get Date because we have a value.
dtStartDate = DateTime.Parse(txtStartDate.Text);
if (txtFirstName.Text.Trim() == "")
{
txtFirstName.BackColor = System.Drawing.Color.Yellow;
lblError.Text = "Please enter first name.";
blnFormIsValid = false;
}
else
{
lblError.Text = "";
txtFirstName.BackColor = System.Drawing.Color.White;
blnFormIsValid = true;
}
if (txtLastName.Text.Trim() == "")
{
txtLastName.BackColor = System.Drawing.Color.Yellow;
lblError.Text = "Please enter last name.";
blnFormIsValid = false;
}
else
{
lblError.Text = "";
txtLastName.BackColor = System.Drawing.Color.White;
blnFormIsValid = true;
}
if (txtPayRate.Text.Trim() == "")
{
txtPayRate.BackColor = System.Drawing.Color.Yellow;
lblError.Text = "Please enter pay rate.";
blnFormIsValid = false;
}
else
{
lblError.Text = "";
txtPayRate.BackColor = System.Drawing.Color.White;
blnFormIsValid = true;
}
if (txtStartDate.Text.Trim() == "")
{
txtStartDate.BackColor = System.Drawing.Color.Yellow;
lblError.Text = "Please enter start date.";
blnFormIsValid = false;
}
else
{
lblError.Text = "";
txtStartDate.BackColor = System.Drawing.Color.White;
blnFormIsValid = true;
}
if (txtEndDate.Text.Trim() == "")
{
txtEndDate.BackColor = System.Drawing.Color.Yellow;
lblError.Text = "Please enter end date.";
blnFormIsValid = false;
}
else
{
lblError.Text = "";
txtEndDate.BackColor = System.Drawing.Color.White;
blnFormIsValid = true;
}
// Compare Dates
if (DateTime.Compare(dtStartDate, dtEndDate) >= 0)
{
txtStartDate.BackColor = System.Drawing.Color.Yellow;
txtEndDate.BackColor = System.Drawing.Color.Yellow;
lblError.Text = "Please make sure that start date is less than end date.";
blnFormIsValid = false;
}
else
{
lblError.Text = "";
txtStartDate.BackColor = System.Drawing.Color.White;
txtEndDate.BackColor = System.Drawing.Color.White;
blnFormIsValid = true;
}
if (blnFormIsValid == true)
{
//Assign a value to the session variable.
Session["FirstName"] = txtFirstName.Text;
Session["LastName"] = txtLastName.Text;
Session["PayRate"] = txtPayRate.Text;
Session["StartDate"] = txtStartDate.Text;
Session["EndDate"] = txtEndDate.Text;
// Sends A Request from the Browser to the server.
Response.Redirect("frmPersonalVerified.aspx");
}
}
更新
我刚刚使用了 .Equals("")... 它不起作用。仍然显示空白页面