can baris
can baris

Reputation: 41

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

Upvotes: 1

Views: 671

Answers (1)

Hrishi
Hrishi

Reputation: 350

Not possible and is not encouraged to do as well.

Upvotes: 1

Related Questions