Textbox.Focus() problem. Repeats SQL by focusing on the field

Asked

Viewed 61 times

0

I have a function that records some information in a table when leaving a TextBox (Leave). But when leaving, the focus returns to the first TextBox. When this occurs it directs the focus as it should, but reinserts the line in the bank with the same information (duplicates). What can I do to adjust?

I’m doing it this way:

public void InsereDados()
    {
        //Pega o valor dos campos e insere no banco
    }

    public void AtualizaGrid()
    {
        //Atualiza as informações no Grid        
    }

    private void Tbnome_Leave(object sender, EventArgs e)
    {          
            InsereDados();
            AtualizaGrid();
            //Volta o Foco para o Primeiro TextBox
            TbCod.Focus();           

    }
  • The first TextBox has some code in the event Enter ? If yes which ?

  • Only on Leave, but I’ve tried to focus on others who have no event and the same thing happens.

  • Somehow the event Leave is not being executed twice? If you put a breakpoint in the first line of the event, there passes there a second time?

  • 1

    The TextBox must be with the AutoPostBak="true"

  • I traded the Leave event for Validating and it worked. Thank you all for your help.

No answers

Browser other questions tagged

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