Debugger does not work

Asked

Viewed 248 times

1

I have the following function in C# and in JAVASCRIPT when I place a stop point (F9) on the function in c# it works normally, but the debugger No, he won’t stop, I’m doing something wrong?

I’m using Visual Studio 2017

 @functions{

        public string obterDado2()
        {
            string Validador = TipoPecaController.validar2;
            return Validador;
        }
        public string alterar()
        {
            TipoPecaController.validar2 = "";
            return TipoPecaController.validar2;
        }
    }

    <script type="text/javascript">
        var vd = "";

        window.onload = function() {
            debugger;
            vd = @obterDado2();
            debugger;
            if (vd == "True") {

                alertify.alert("Aviso", "Esse Tipo de Peça já existe, tente cadastrar um diferente", function () {
                    alertify.message('OK');
                });
                vd = @alterar();
            }
            else if (vd == "Trues") {
                    alertify.alert("Aviso", "Essa sigla já existe, tente cadastrar uma sigla diferente", function () {
                        alertify.message('OK');
                    });
                    vd = @alterar();
            }
        }
    </script>
  • you’re giving F12 in the browser?

  • Well, I’m a beginner and I didn’t know it was necessary the F12, I’ll test, thank you

  • This is for if you want to debug without ide.. I don’t know if that’s your case

  • 1

    I’d like it to go through the ide, but thanks, I’ll get to learn about debugging by the browser

  • What kind of VS project are you talking about?

  • I don’t know exactly understood the question, but I work with Asp.net

  • It seems to me Razor Pages, the question is whether you are talking about MVC, Razor Pages, Web Forms, Blazor or other structure.

  • Well, I don’t know if I’m going to answer this question correctly, as I said I’m a beginner, but it must be Web Forms, because I’m working with forms, I’m not in the company anymore, but I’m going to post the code all tomorrow when I get there

  • 1

    If you want to debug javascript by VS 2017 you have to use/navigate that page that it opens automatically when you press F5

Show 4 more comments

1 answer

2


Except for some points to be noted here, you are declaring your strings in javascript without using quotes...

The result of vd = @obterDado2(); would be vd = True; and not vd = "True";, see the correction.

@functions{

    public static class TipoPecaController
    {
        public static string validar2 { get; set; } = "True";
    }

    public string obterDado2()
    {
        string Validador = TipoPecaController.validar2;
        return Validador;
    }
    public string alterar()
    {
        TipoPecaController.validar2 = "";
        return TipoPecaController.validar2;
    }
}

<script type="text/javascript">
        var vd = "";

        window.onload = function() {

            vd = "@obterDado2()";

            if (vd == "True") {

                alertify.alert("Aviso", "Esse Tipo de Peça já existe, tente cadastrar um diferente", function () {
                    alertify.message('OK');
                });
                vd = "@alterar()";
            }
            else if (vd == "Trues") {
                    alertify.alert("Aviso", "Essa sigla já existe, tente cadastrar uma sigla diferente", function () {
                        alertify.message('OK');
                    });
                    vd = "@alterar()";
            }
        }
</script>

Then... the statement debugger, is for the browser only. Visual Studio will not pause execution at this point. To debug from the IDE just place a breakpoint where you want to stop...

inserir a descrição da imagem aqui

... But you need to make sure that the debuggar JS functionality is enabled on Tools -> Options -> Debugging

inserir a descrição da imagem aqui

  • Can you put a breakpoint in an if? I can only put where there is a code c#

  • @Jeffhenrique did you check the debugging settings? Are you taking VS in Administrator mode? Fixed the errors I pointed out in javascript?

  • I fixed the errors, and checked the settings, but I did not run in administrator mode, I will try

  • Running as administrator worked out, thanks Leandro

Browser other questions tagged

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