Read out result of a PageMethod into a jQuery-script

Posted by Jan-Frederik Carl on Stack Overflow See other posts from Stack Overflow or by Jan-Frederik Carl
Published on 2010-03-12T16:12:16Z Indexed on 2010/03/16 12:06 UTC
Read the original article Hit count: 270

Filed under:
|
|

Hello, I am quite a jQuery novice and try to read out the result of a PageMethod into my jQuery script. I have a ScriptManager installed and the following WebMethod:

[WebMethod(EnableSession = true)]
    public static string CheckSystemDefault(string _id)
    {
        int id = Convert.ToInt16(_id);
        addressTypeRepository = new AddressTypeRepository();

        AddressType addressType = addressTypeRepository.GetById(id);

        if (addressType.IsSystemDefault == true)
            return "IsSystemDefault";
        else
            return "IsNotSystemDefault";
    }

I use this to check if an object has the property IsSystemDefault.

In the script, I hand over the id from the url and want to evaluate the result:

var id = $(document).getUrlParam("id");
var check = PageMethods.CheckSystemDefault(id);
if (check == "IsSystemDefault") {
...
}
if (check == "IsNotSystemDefault") {
...
}

But as a result, the variable "check" is undefined. What do I have to change?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about pagemethods