Chrome does not apply Addclass before calling window.confirm

0

Problem:

Chrome is not rendering my class addclass before calling my confirmation window window.confirm is like if it got stuck and was released only after the confirmation.

What I did was put the call of the function ConfirmaExclusao to OnClientClick of a image button that is within a TemplateField in gridview , the intent of the commit when it returns false is not to call the% RowCommand in which effective deletion.

This solution for IE 9, 10 and 11 works, but pro chrome does not ...

Example:

Have an example here of the problem link can see that for chrome the class is applied after the confirmation window exit .

My javascript functions:

function MarcarLinha(linha) {
    //Soma 2 na linha (1 linha do Cabeçalho e mais uma poque o TR da grid começa em 1, não em zero)
    linha = linha + 2;

    //Limpa todas as marcações
    $('[id$=gridViewListaCondicoesComlRCTRVI]').find('tr').each(function (row) {
        $(this).removeClass('hover_row');
    });

    $('[id$=gridViewListaCondicoesComlRCTRVI] tr:nth-child(' + linha + ')').addClass('hover_row');
}

function ConfirmaExclusao(linha) {
    MarcarLinha(linha);

    //Confirmar a exlusão
    if (window.confirm('Deseja realmente excluir este registro?'))
        return true;
    else {
        //$('[id$=gridViewListaCondicoesComlRCTRVI] tr:nth-child(' + linha + ')').removeClass("hover_row");
            return false;
    }
}

My ImageButton inside the gridview:

<ItemTemplate>
    <asp:ImageButton ID="imgBtnExcluir32" runat="server" CommandName="Excluir" CommandArgument='<%#Container.DataItemIndex%>'
    ImageUrl="~/images/delete.png" OnClientClick='<%# "return ConfirmaExclusao(" + ((GridViewRow)Container).RowIndex + ");" %>' />
</ItemTemplate>
    
asked by anonymous 10.08.2017 / 16:18

1 answer

0

JavaScript is an interpreted function, and the browser interprets it line by line. However, the browser does this very quickly where it ends up running the lines below the function call even before the function is executed.

To avoid this kind of problem, you can use the callback technique:

function MarcarLinha(linha, callback) {
    //Soma 2 na linha (1 linha do Cabeçalho e mais uma poque o TR da grid começa em 1, não em zero)
    linha = linha + 2;

    //Limpa todas as marcações
    $('[id$=gridViewListaCondicoesComlRCTRVI]').find('tr').each(function (row) {
       $(this).removeClass('hover_row');
    });

    $('[id$=gridViewListaCondicoesComlRCTRVI] tr:nth-child(' + linha + ')').addClass('hover_row');

    callback(); // A função passada será executada aqui
}

function ConfirmaExclusao(linha) {
    MarcarLinha(linha, function() {
        //Confirmar a exlusão
        if (window.confirm('Deseja realmente excluir este registro?'))
            return true;
        else {
            //$('[id$=gridViewListaCondicoesComlRCTRVI] tr:nth-child(' + linha + ')').removeClass("hover_row");
            return false;
        }
    });
}

I hope I have helped!

    
11.08.2017 / 03:38