Below is the code of my simple page's submit button click. I am submitting an empty form but no server validation error messages are showing. What's wrong with my code? When I click on submit, the page just turns blank and nothing happens. I am also unable to attach the debugger.
When I am building my website project, it is not showing any compilation error either. I don't know what I am doing wrong.
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");
}
}
Update
I just used .Equals("")... it's not working. Still blank page is showing up
Equals()method. Please check this and this.String.Emptywork for you?