简体   繁体   中英

Calling c# function in javascript

I've been trying to call ac# function in javascript this way :

function x() {
    PageMethods.F1(onSucess, onError);

    function onSucess(result) {
       alert('Success');
    }
    function onError(result) {
       alert('Something wrong.');
    }
}
[WebMethod]
public static boolean F1()
{
    return true;
}

<asp:Button ID="Button1" runat="server"  OnClientClick="x(); return false"    Text="Button"  />

But I don't get any result, I mean neither of the alert messages pops up. What exactly is wrong ?

ScriptManager上将EnablePageMethods设置为true

<asp:ScriptManager EnablePageMethods="True" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM