0
Good evening, I need to reference a component PlaceHolder
Asp.Net
in a static method in the code-behind
C#
, this method is called via AJAX
for front-end
see the code:
Method call by the Form aspx front-end:
<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 get the message "An object reference is required for the non-static field, method, or property"
in the component PlaceHolder1
.
How do I make the method see the Placeholder1 component?
No way !!!! ..... will have to use another way! what you want to do?
– novic
@Diegorafaelsouza Andamento is a class with a function that returns a "Make_table_html" string that mounts html to a table with people names
– Evandro
If the method needs to access an instance member it should not be static.
– Jéf Bueno
@Evander returns a
JSON
and work the information on your front, since you are usingAjax
! directly this is not possible, or even returns the html changing the returndataType:'html'
in hisajax
! have two options there.– novic
@Virgilionovic I will try to model returning a JSON, you would have an example in code to guide me.
– Evandro
@Evandro an example: https://cbsa.com.br/post/web-service--retornar-json-com-aspnetc.aspx
– novic
@Virgilionovic so it will work in return
$('.resultado').text(data.d);
I assemble html, I will test and put here– Evandro