Static method does not recognize fields in aspx

Asked

Viewed 32 times

0

This method needs to be Static

[WebMethod]
        public void ValidaSenhaAntiga(object sender, EventArgs e)
        {
            long CPF = Helper.DFrmtCPF(cpf.Value);
            string senhaAtual = SenhaAtual.Value;
            bool senhaAt = ws_usuario.getSenhaAtual(senhaAtual);
            if (!senhaAt)
                lblMsg1.Text = Helper.ExibirMsgAlerta("A senha não confere.");
        }

The problem is that when I put Static it does not recognize SenhaAtual.Value and neither cpf.Value, because these fields come from a page aspx. I am using the PageMethods and from the research I’ve done on the Internet it only works with public static. What I am doing is for javascript to execute a method in the code Behind, to validate a password, that is, in the Passwords field the user enters the current password and this function searches in the BD and compares with what the user typed and returns true or false. How do I use the PageMethods, methodically public static and fields of aspx? No js have it, but I need to get better:

function ValidaSenhaAtual() {
    PageMethods.ValidaSenhaAntiga(true, false);
}

This edition, I tried to do otherwise. I created this js function

function ValidaSenhaAtual() {
    $.get('minha_pagina.aspx/ValidaSenhaAntiga', {
        NovaSenha: $('#conteudo_SenhaAtual').val()
    }, function (data) {
        if (data.senhaAt === true)
            alert('ok');
    });
}  

To call this method in code Behind

[WebMethod]
        public void ValidaSenhaAntiga(string NovaSenha)
        {
            //long CPF = Helper.DFrmtCPF(cpf.Value);
            //string senhaAtual = SenhaAtual.Value;
            bool senhaAt = ws_usuario.getSenhaAtual(NovaSenha);
            //if (!senhaAt)
               // lblMsg1.Text = Helper.ExibirMsgAlerta("A senha não confere.");
        } 

This approach doesn’t work either. I think this $.get('minha_pagina.aspx/ValidaSenhaAntiga is wrong. When you reach this line, it skips the function.

  • For better clarification, could kindly put the error presented?

  • 1

    @Hyagosantos, actually the error is in design time, that is, not even compile. The fields referring to the page are already underlined in red.

  • 1

    And why don’t you send these fields by parameters as well?

  • 1

    "i put Static it does not recognize Senhaatual.Value" because SenhaAtual should be a member of the class and is not Static. If a method is Static, all class members who access tbm must be Static, or would have to create within the method an instance of the class itself

  • 1

    @Ricardopunctual believe that because in the . aspx SenhaAtual should be the field of his form, in which case it is not possible to use it as static.

  • 1

    @Brunowarmling itself in this case would not be possible to be Static, I commented that because the question does not show where the Senha current, but the problem is that I commented, the fact that it is not Static

Show 1 more comment
No answers

Browser other questions tagged

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