I have a C# class Data, stored in Data.cs, and there I have a simple method PrintName:
void PrintName(string name)
{
Label lblName = new Label();
lblName.Text = name;
cph.Controls.Add(lblName);
}
where cph is a ContentPlaceHolder of the asp.net page, where an instance of Data is created. And I need to pass some data from jQuery client side to C#, and I am trying this code:
function Print() {
$.ajax({
type: "POST",
url: "Data.cs/Data.PrintName",
data: '{name: "Steven" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
jAlert('Success', 'Alert Dialog');
},
failure: function () {
jAlert('Failure', 'Alert Dialog');
}
});
}
$(document).ready(function () {
Print();
}
The problem is that I am trying to call not the asp.net page itself, but a C# class, those instance has access to the page through cph variable. Is it possible to solve this somehow and pass data to the needed instance of the class?