Well how webforms is setup you can't actually get to the code behind file since that would require you to go through the entire page life cycle. You can't just have some method in your code behind file and try to just target it.
So you need to either make a web service or what I like to do is use a generic handler.
So you would go to add - add new item - generic handler(.ashx)
It would generate a file like this(the follow code has some more stuff in it that is not generated by default).
<%@ WebHandler Language="C#" Class="FileNameOfGenricHandler" %>
using System;
using System.Web;
public class FileNameOfGenricHandler: IHttpHandler {
public void ProcessRequest (HttpContext context) {
// use context.Request to get your parameter fields that you send through ajax.
int ID =Convert.ToInt32(context.Request["sendID"]);
// do something with the variable you sent.
// return it as a string - respone is just a string of anything could be "hi"
context.Response.ContentType = "text/plain";
context.Response.Write(response);
}
public bool IsReusable {
get {
return false;
}
}
}
On jquery side
// Post to the path like this ../FolderName/FolderName/FileName.ashx(or whatever you stuck your generic handler file).
$.post('../FolderName/FileNameOfGenricHandler.ashx', { sendID: id }, function(response)
{
alert(response)
});
One downside with the generic handler though is for every different ajax request you want to make you will need its own generic handler. So if you want to create a user, delete a user and update a user through ajax you will have to have 3 generic handlers.
Here is a similar tutorial I used.
http://sites.google.com/site/spyderhoodcommunity/tech-stuff/usingjqueryinaspnetappswithhttphandlersashx