I am calling a pagemethod function in codebehind (asp.net) from my javasript function

1. Event Fires

2. Main Javascript Function is called

3. Inside the Main Function i am calling the pagemethod and and based on the result of pagemethod i have to send true or false as return value.

var x=0;

function main()

{

Pagemethods.processomefunction(processresult)

if (x==0)

{return false;}

else

{return true;}

}

function processresult(result)

{

x=result;

}

PROBLEM:

i expect the pagemethod to be executed first and then based on that value of x the next statement to be executed, but what happens is

if (x==0)

{return false;}

else

{return true;}

is executed first before pagemethod get executed and so it always return false.

Is there any solution for this problem?

thanks and regards