使用PageMethods在javascript中调用c#函数

使用PageMethods在javascript中调用c#函数

问题描述:

我一直试图用Javascript调用ac#函数:

I've been trying to call a c# 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?

您是否在脚本管理器中添加了 EnablePageMethods = true





Have you added the EnablePageMethods = true in script manager


<asp:ScriptManager ID="ScriptManager" runat="server"
      EnablePageMethods="true" />


请参阅..

在JavaScript函数中调用c#函数 [ ^ ]

http://forums.asp.n et / t / 1281169.aspx [ ^ ]

http://stackoverflow.com/questions/6321009 / calling-c-sharp-method-using-javascript [ ^ ]

http://stackoverflow.com/questions/18036973/calling-c-sharp-function-in-javascript [ ^ ]

http://forums.asp.net/t/1379633.aspx [ ^ ]
See..
call c# function in JavaScript Function[^]
http://forums.asp.net/t/1281169.aspx[^]
http://stackoverflow.com/questions/6321009/calling-c-sharp-method-using-javascript[^]
http://stackoverflow.com/questions/18036973/calling-c-sharp-function-in-javascript[^]
http://forums.asp.net/t/1379633.aspx[^]