How to display a confirmation message when clicking delete from the grid option?

Asked

Viewed 2,964 times

3

I’m trying to do this job, but I’m not getting it!

Page.ClientScript.RegisterStartupScript(objLivros.GetType(), "confirm", "confirm('Tem certeza que deseja excluir esse item?')", True)
  • have tried using Alert() ?

  • I used it, but there was only the message "OK"

  • I answered below, try to do this way.

  • You put Scriptmanager on your page?

  • See if that link help you.

5 answers

1

MessageBox.Show() is what you needed:

Advanced way, with Handles to if user click Yes, no or cancel.

  REM esse Label é onde vamos usar o nosso GoTo se ele ignorar a mensagem.
start:

  REM você pode adicionar mais argumentos...
  Dim Resultado As Int32 = MessageBox.Show("Deseja realmente excluir esse item?", "Título", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Info)

  'MessageBoxButtons -> Botões em que vão aparecer na janela
  'MessageBoxIcon    -> O ícone que vai aparecer do lado da janela

  Select Case Resultado
      Case DialogResult.OK 'Ou DialogResult.Yes
          REM aqui fica o código quando o usuário clicar no 'Sim'.
      Case DialogResult.Cancel Or DialogResult.No
          REM e aqui o código se ele clicou em não, ou cancelar.
      Case Is Nothing
          REM aqui se ele não pressionou nenhum botão, se ele ignorou a janela...
          GoTo start ' Aqui vai retornar para o label start...
      Case Else
          REM outro botão que ele aperto...
  End Select

Simplified way, just yes or no.

     Dim result As DialogResult = MessageBox.Show("Deseja realmente excluir esse item?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
     Select Case result
        Case Windows.Forms.DialogResult.Yes
           REM decidiu colocar sim...
        Case Windows.Forms.DialogResult.No
           REM decidiu colocar não...
     End Select
  • I think he was asking how to do the Handler at the time the grid is clicked.

  • 1

    Just put this code in the event Control.MouseClick, since it is a (if it is a) Windowsforms control, it is supported

0

Simply:

If MsgBox("Tem certeza que deseja sair?", vbYesNo, "Confirmação") = vbYes Then
            If vbYes Then
                Me.Close()
            End If
            If vbNo Then
            Else
            End If
        End If

0

Within the class, include this method, and see if it will give the result you expect:

   protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
                string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"];

                if (eventTarget == "ConfirmacaoCliente")
                {
                    if (eventArgument == "true")
                    {
                        //Faça algo caso o cliente clique em 'Ok'
                    }
                    else
                    {
                        //Faça algo caso o cliente clique em 'Cancel'
                    }
                }
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            string myScript = @"<script type='text/javascript' language='javascript'>
                                    var confirmation = window.confirm('Deseja excluir este item?');
                                    __doPostBack('ConfirmacaoCliente', confirmation);
                                </script>";
            ClientScript.RegisterStartupScript(GetType(), "key", myScript);
        }

Source of the code

0

Try to use alert()

follows the model I found in W3C:

<button onclick="myFunction()">Try it</button>


function myFunction() {
    alert("Hello\nHow are you?");
}

  • Alert does not work... I want to do this when deleting from the grid, there in Rowcommand, if it is yes then it falls into my delete function, if it is not it leaves the sub!

0

Why not use msgbox? It would look something like this:

Dim decisao As Integer = MsgBox("Deseja realmente excluir esse item?", MsgBoxStyle.Question + MsgBoxStyle.OkCancel)

    If decisao = 1 Then

        'Código de exclusão aqui
    Else

        'Aqui nada acontece...
End If

You can put this simple snippet anywhere, for example in the event click to delete from your grid...

Browser other questions tagged

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