0

Tried to look after this, and Couldn't find a good explaination..

    function updateusers() {
    var columns = ["username", "password", "email", "adminlevel", "usertype", "gender", "regdate", "lastlog"]
        for (var row = 2; row <= $('#usertable').children().children().length; row++) {
            for (var col = 0; col < 8; col++) {
                if ($('[name=' + row + '_' + columns[col] + ']').val() != 0) {
                    ###ASP.Net Function###
                    UpdateIT($('[name=' + row + '_' + columns[col] + ']').val())
                    ###ASP.Net Function###
            }
        }
    }
}

I Understood I can do it with Ajax, But Couldn't understand properly How.. I Got a Function Called UpdateIT in my Default.aspx, and I want to call it

0

1 Answer 1

1

Try this.

function updateusers() {
        var columns = ["username", "password", "email", "adminlevel", "usertype", "gender", "regdate", "lastlog"]
            for (var row = 2; row <= $('#usertable').children().children().length; row++) {
                for (var col = 0; col < 8; col++) {
                    if ($('[name=' + row + '_' + columns[col] + ']').val() != 0) {
                        ###ASP.Net Function###
                        var param = {};
                        param.name =  row + '_' + columns[col];
                        $.ajax({
                           type: 'POST',
                           url: '<%= ResolveUrl("~/default.aspx/UpdateIT") %>',
                           data: JSON.stringify(param),
                           contentType: 'application/json; charset=utf-8',
                           dataType: 'json',
                           success: function (msg) {
                           alert(msg.d)
                       }
                       });
                       ###ASP.Net Function###
                }
            }
        }
    }

see this link too

Calling a webmethod with jquery in asp.net webforms

EDIT------------------

I implement this test and it´s worked here. Try it.

cs

[WebMethod]
public static void UpdateIT(string name)
{
    throw new Exception("I´m here");
}

js

function tryCallUpdateIT() {

    var param = {};
    param.name = '1' + '_' + "value";
    $.ajax({
        type: 'POST',
        url: 'default.aspx/UpdateIT',
        data: JSON.stringify(param),
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (msg) {
            alert(msg.d)
        }
    });

}
Sign up to request clarification or add additional context in comments.

6 Comments

What you mean by Json format?, What I'm sending over there? the parameters for the ASP.Net Function?
I change the code to use the parameters like json. The function that you will call em seerver side need to have [WebMethod] annotation, and param.name, the property name os param need to be the same name os the method parameter.
I've Changed it as you said, and changed also the directory position (url: '<%= ResolveUrl("~../default.aspx/updateit") %>',) added error: alert("Error") and it keep alerting me that I got an error
try use default.aspx/UpdateIT, can you send the error message?
Does UpdateIT have with annotation [WebMethod]?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.