Call Javascript function from WebMethods

1.3k views Asked by At

I am using Page Methods in ASP.NET, in the code behind I have written a method which should call a JavaScript function for each loop, then it should come back and continue the loop.

Is it possible?

[WebMethod]
public static void GetStatus()
{
    for (int i = 0; i < 10; i++)
    {
        System.Threading.Thread.Sleep(500);
        //Call javascript function
    }

}

Any help will be greatly appreciated, thanks.

2

There are 2 answers

1
Joe Enos On

The client and server don't talk to each other - sounds like you need to call the web method over and over again from javascript for each value.

0
Perpetualcoder On

It looks like you are trying to implement a call back mechanism. Take a look at this MSDN article. From what i understand you want to do something like: 1. Call a page/web method via JS 2. Call some JS method when page/web method returns or is done.

Maybe u should expand the question