简体   繁体   English

如何从JavaScript调用asp.net函数的非静态方法?

[英]how to calling asp.net function from javascript for the non-static method?

i am calling asp.net function from javascript using this code as given below : but i need to call non-static method. 我正在使用以下代码从JavaScript调用asp.net函数:但我需要调用非静态方法。 when i remove the static field function not firing. 当我删除静态字段功能不触发。 There is any way to do this ? 有什么办法可以做到? thank you 谢谢

public partial class Test : System.Web.UI.Page
{
   [WebMethod]
   public static string HelloWorld(string name)
   {
       return string.Format("Hi {0}",name);
   }
}


<script type="text/javascript">
function GreetingsFromServer() {
    var name = 'Jalpesh';
    PageMethods.HelloWorld(name,OnSuccess, OnError);
    return false;
}
function OnSuccess(response) {
    alert(response);
}
function OnError(error) {
    alert(error);
}

不可能,也不鼓励这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从静态Web方法调用ASP.NET页面非静态方法 - Calling ASP.NET page non-static methods from static web methods ASP.NET:如何使用客户端AJAX脚本调用非静态页面方法? - ASP.NET: How to call non-static page method with client AJAX script? 如何使用Threading.Timer在ASP.NET C#上的公共非静态方法上循环? - How to use Threading.Timer for a loop on a public non-static method on ASP.NET C#? 在ASP.NET Core 2.1的Application Startup上调用非静态类来播种数据库 - Calling a non-static class to seed database on Application Startup in ASP.NET Core 2.1 asp.net c# - 字段初始值设定项不能引用非静态字段,方法或属性 - asp.net c# - A field initializer cannot reference the non-static field, method or property 字段初始化程序无法引用ASP.Net MVC Controller中的非静态字段,方法或属性 - A field initializer cannot reference the non-static field, method, or property in ASP.Net MVC Controller 如何从ASP.NET中调用[Web方法]的JQuery在javascript函数中返回false - How to return false in javascript function from JQuery calling [web method] in asp.net 在静态方法中调用非静态方法 - Calling non-static methods in a static method 从.NET Core 2.0控制器使用DbContext调用非静态方法 - Calling non-static method using DbContext from .NET Core 2.0 Controller 如何在asp.net-4.5的静态“ webmethod”函数中获取非静态值 - How to get a non-static value in a static “webmethod” function in asp.net-4.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM