Enable a button after entering password

Asked

Viewed 186 times

-1

I need some help, but I don’t know how I can make this code.

I have a form and in this form I have a button that deletes in an SQL table, I want to make the button is disabled and to enable it I want to make the user type a password.

Follow the code of the button that calls the form to enter the password.

private void btnExcluir_Click(object sender, EventArgs e)
{
    frmExclusao excluir = new frmExclusao(txtID.Text);
    excluir.Show();
}

follow the password form code.

private void btn_Ok_Click(object sender, EventArgs e)
{
    if (MessageBox.Show("Confirma a exclusão do cadastro", "Atenção", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "DELETE FROM tbl_amostra WHERE ID = '" + txtID.Text + "'";
        cmd.Connection = conex;

        conex.Open();
        cmd.ExecuteNonQuery();
        conex.Close();
    }
  • Could you give us more details? Is your project web? If so, are you using a jQuery, Angular...? Edit your question in more detail, so it’s easier to help you.

  • Good morning. No and web and an executable in c#, I need to do the following when open the form the button is disabled, when I click with the mouse on the disabled button it open a new form, enter a password and give ok and then yes, enable the button to delete the data.

  • What you’ve achieved so far?

  • Your project is Win Forms, WPF...? The more details you can provide, the easier we can answer the question. If possible put a print screen on the question to get a better idea of what you want to do.

  • You want to click a disabled button? ._.

  • That’s right click on a disabled button it call another form, asking for a password to enable the button

Show 1 more comment

1 answer

3


Understanding that your project is winform when you say "I have a form", use the Textchanged event from Textbox:

private void textBox1_TextChanged(object sender, EventArgs e)
{
    ButtonDelete.Enable = (textBox1.Text == "1234");
}
  • Rovann but in this case the button will be in another form, because the field with the textbox to enter the password is not the same form as this button, your code above will work?

  • show the code where you call the second form, by the first, and the form code that enters the password, which then adéquo the code to your situation.

  • 1

    It worked right here with the option you gave above, adjusted the form and worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.