I am developing an ASP.Net application where I'm running into some trouble calling a function in the code behind using JavaScript.
This is the JavaScript function I'm trying to run:
PageMethods.EditRecord($(this).data("row-id"));
And this is my code behind function:
public void EditRecord(string logID)
{
lblLogID.Text = logID;
ClientScript.RegisterStartupScript(GetType(), "Show", "<script> $('#edit').modal('toggle');</script>");
}
If I run it like this I get the following error:
Uncaught ReferenceError: PageMethods is not defined
I did some reading and realized that I'm supposed to change public void EditRecord(string logID)
to public static void EditRecord(string logID)
.
Unfortunately, when I attempt that then lblLogID
and ClientScript
give me hassles with the following error:
An object reference is required for the non-static, method, or property...
How can I work around this to run my code behind method using JavaScript without all these drawbacks?