praveen praveen - 2 months ago 5
Ajax Question

ajax call is not working for the c# method

i want to call the unlock method on closing or redirecting other page, so i have used ajax call. but the method unlock is not firing. please let me know what i am doing

[WebMethod]
public void Unlock()
{
CreateProject_BL _objcreatebl = new CreateProject_BL();
_objcreatebl.upd_lockedBy(Convert.ToInt32(Request.QueryString["project_id"]), "");
}

function HandleOnclose() {
$.ajax({
type: "POST",
url: "ProjectDetails.aspx/Unlock",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
}
window.onbeforeunload = HandleOnclose;

Answer

Where you passing project_id in your ajax call??? pass project_id in your method

 [WebMethod]
public void Unlock(string project_id)
{
    CreateProject_BL _objcreatebl = new CreateProject_BL();
    _objcreatebl.upd_lockedBy(Convert.ToInt32(Request.QueryString["project_id"]), "");
}

and then rewrite ajax call as

function HandleOnclose() {
        $.ajax({
            type: "POST",
            url: "ProjectDetails.aspx/Unlock",
            contentType: "application/json; charset=utf-8",
            data : "{project_id:'1234'}",
            dataType: "json"
        });
    }
window.onbeforeunload = HandleOnclose;
Comments