简体   繁体   中英

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. 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);
}

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

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