Referencing non-static object in a static method

0

Good evening, I need to reference a PlaceHolder Asp.Net component in a static method in code-behind C# , this method is called via AJAX by front-end see code:

Call the method by the front end Form aspx:

<script type="text/javascript">
    function CallCsharpFunction(andamento_id) {
         try {
            $.ajax({
                type: "POST",
                url: 'Processo.aspx/AtuarNoProcesso',
                data: "{'AndamentoID':'" + andamento_id + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: location.reload(true), 
                error: function (msg) {
                    alert(msg.d);
                }
            });
        } catch (err) { }
    }
</script>

The Method in Code-Behind C #:

[System.Web.Services.WebMethod]
public static string AtuarNoProcesso(int AndamentoID)
{   
    PlaceHolder1.Controls.Add(new Literal
    {
          Text =  Andamento.Make_Table_Html(Convert.ToInt32(AndamentoID)) });
    }
}

But you get the message "An object reference is required for the non-static field, method, or property" in the PlaceHolder1 component. How do I see the PlaceHolder1 component?

    
asked by anonymous 23.02.2018 / 00:51

1 answer

0

As per the staff tip I set up the html table with the information in the JSON return of the call Ajax , see how it was:

<script type="text/javascript">
    function GetData(andamento_id) {
        var $tbl = $('#tbl');
        $.ajax({
            url: 'Andamento.aspx/GetComentarioAndamento',
            data: "{'AndamentoID':'" + andamento_id + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            type: "POST",
            success: function (data) {
                debugger;
                if (data.d.length > 0) {
                    for (var i = 0; i < data.d.length; i++) {
                        $tbl.append('<tr><td>' + data.d[i].ComentarioTexto
                            + '</td><td>' + data.d[i].DataHoraComentario
                            + '</td><td>'
                            + "<div class='row centered'><div class='user-block'><img src='"
                            + data.d[i].FotoProfile + "' data-toggle='tooltip' title='"
                            + data.d[i].NomeAdvogado + "' class='img-circle img-bordered-sm'></div></div>"
                            + '</td></tr>');
                    }
                }
            }
        });
    }
</script>

//tabela
<table id="tbl" class="table table-hover">
   <tr>
   </tr>
</table>
    
24.02.2018 / 00:43