Reputation: 41
I have a registration where the user will enter the following details:
Email address, Password, Confirm password, A drop down menu with option Employee or Contractor.
When Employee is selected they are not required to provide start date but for contractor they have to provide start date.
protected void Button1_Click(object sender, EventArgs e)
{
{
{
SqlConnection sqlCon = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand("UpdateRequest", sqlCon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "UpdateRequest";
cmd.Connection = sqlCon;
cmd.Parameters.AddWithValue("@EmailAddress", txtEmailAddress.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@ConfirmPassword", txtConfirmPassword.Text);
cmd.Parameters.AddWithValue("@JobRole", ddJobRole.Text);
cmd.Parameters.AddWithValue("@StartDate", txtStartDate.Text);
SqlParameter rpv = new SqlParameter();
rpv.DbType = DbType.Int32;
rpv.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(rpv);
try
{
sqlCon.Open();
cmd.ExecuteScalar();
int retValue = Convert.ToInt32(rpv.Value);
if (retValue == 10)
lblMessage.Text = "Request was sent successfully!";
if (retValue == 11)
lblMessage.Text = "*Email Address is already registered.";
if (retValue == 12)
lblMessage.Text = "*Passwords do not match.";
if (retValue == 13)
lblMessage.Text = "Sorry, Your application was already denied earlier.";
}
catch (Exception)
{
lblMessage.Text = "";
}
}
}
}
protected void ddJobRole_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddJobRole.SelectedValue == "Contractor")
{
RequiredFieldValidator27.Enabled = true; //Initally disabled it
}
else
{
RequiredFieldValidator27.Enabled = false;
}
}
Here the problem is whenever I select any option from the drop down the form loads again and asks password and confirm password for the second time. Can anyone tell me what the problem is?
Upvotes: 1
Views: 61
Reputation: 66641
The password and the confirmation password fields are not kept their values after the post back for security reasons. This input controls are not have the same behavior as the rest controls.
Now from the code I see, you do not actually need to make full post back for this behavior on code behind, you can easy use javascript and do the same on client side with out post back, and without loose the input of the password.
Upvotes: 1