0

I am using a script manager and I am calling a JavaScript function from a button. The problem is that in this function, I am calling a web service. I always get the error callback, even if there is no code in the web service function. I do not know why this happens.

This is my button:

<button id="button" onclick="save()"></button>

This is the JS function:

function save() {
    var id = document.getElementById("label").innerHTML;
    var text = document.getElementById("textarea").value;
    alert(text);
    // OPUS.WebService1.saveChange(id, text, success, error);
    OPUS.WebService1.saveChange( 1, "test", success, error);    
}

function success(result) {
    alert(result);
    // __doPostBack('UpdatePanel', '');
}

function error(error) {
    var stackTrace = error.get_stackTrace();
    var message = error.get_message();
    var statusCode = error.get_statusCode();
    var exceptionType = error.get_exceptionType();
    var timedout = error.get_timedOut();
    var RsltElem =
        document.getElementById("test").innerHTML =
        "Stack Trace: " + stackTrace + "<br/>" +
        "Service Error: " + message + "<br/>" +
        "Status Code: " + statusCode + "<br/>" +
        "Exception Type: " + exceptionType + "<br/>" +
        "Timedout: " + timedout;
}

This is my web service function:

[WebMethod]
public bool saveChange(int id, string newText)
{
    /*OPUSPUBAPPEntities1 model;
    model = new OPUSPUBAPPEntities1();
    var test = model.MESSAGEs.First(m => m.MessageID.Equals(id));
    test.Msg = newText;
    // var t = model.SaveChanges();
    // return t.ToString();*/
    return true;
}

There is another weird thing happening as well, which is that the label that I changed in the error function takes the values and then disappears. I do not know why either, can anyone please help?

jvdhooft
  • 657
  • 1
  • 12
  • 33
ADA15
  • 86
  • 15

1 Answers1

0

if any anyone is interested, here is the answer

i should make a return false in the function save() and then use this

       `<button id="button" onclick="return save(); "></button>`

the reason is in here

I hope this would help

Community
  • 1
  • 1
ADA15
  • 86
  • 15