I'm working on a web application and I need to fire a c# function from my code behind when a tree button is pressed on the page. I found some code that finds the node for me, However, the c# function doesn't seem to be recognized when trying to call it from JS.
<script type = "text/javascript">
function OnLoad() {
var links = document.getElementById("<%=navTree.ClientID %>").getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
links[i].setAttribute("href", "javascript:NodeClick(\"" + links[i].id + "\", \"" + links[i].getAttribute("href") + "\")");
}
}
window.onload = OnLoad;
function NodeClick(id, attribute) {
//Do Something
alert(nodeLink.innerHTML + " clicked" + PageMethods.node_Click());
eval(attribute);
}
</script>
and here's my C# code:
[WebMethod]
public static string node_Click()
{
return "@#$";
}
If I remove the PageMethods.node_Click() call from the alert then it works fine, but not with the call. I also noticed when typing PageMethods. my function doesnt appear on the pop list after the period (in VS)
Any ideas?
Also, heres my cs file:
public partial class SiteMaster : MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string node_Click()
{
return "@#$";
}
}
PageMethods? Is that the name of the code behind class? Somehow I don't think it is.