我一直在尝试以这种方式在 javascript 中调用 c# 函数:
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" />
但是我没有得到任何结果,我的意思是两个警告消息都没有弹出。到底哪里出了问题?
最佳答案
在 ScriptManager
上将 EnablePageMethods
设置为 true。
<asp:ScriptManager EnablePageMethods="True" />
关于javascript - 在javascript中调用c#函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18036973/