使用PageMethods在javascript中调用c#函数 [英] Calling c# function in javascript using PageMethods

查看:111
本文介绍了使用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" />


请参阅..

< a href =http://www.codeproject.com/Questions/218630/call-csharp-function-in-JavaScript-Function>在JavaScript函数中调用c#函数 [ ^ ]

< a href =http://forums.asp.net/t/1281169.aspx> 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[^]


这篇关于使用PageMethods在javascript中调用c#函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆