Javascript function does not perform

Asked

Viewed 83 times

0

I have a c# check that if it is true, runs the following javascript function:

@{
    if (!string.IsNullOrEmpty(TipoPecaController.MsgExcluir))
    {
        if (TipoPecaController.MsgExcluir == "3")
        {
            <script type="text/javascript">
                window.onload = function MensagemErro() {
                    debugger;
                    try {
                        alertify.alert("Existem itens utilizando este Tipo de Peça.", function () {
                            alertify.message('OK');
                        });
                    } catch (err) {
                        debugger
                    }
                    try {
                        alertify.error("Código e GrupoProduto já existente");
                    } catch (err) {
                        debugger;
                    }
                }
                @TipoPecaController.MsgExcluir = "";
            </script>
        }
    }
}

But even if the verification is true, the javascript code is not executed

  • 1

    That’s on a page .cshtml, MVC?

2 answers

3

2


The .ready(), will perform the action as soon as you finish loading the page, counting that you use JQuery for having codes .Net:

<script type="text/javascript">
    $(document).ready(function() {
      console.log('Teste')
    })
</script>

Or you can try without assigning a name to your function using only Javascript pure:

<script type="text/javascript">
    window.onload = function() 
    {
      console.log('Teste')
    }
</script>

Browser other questions tagged

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