Search code examples
c#javascriptasp.netpagemethods

returning value from page method in asp.net


I have a page method which is doing some complicated validation on server side. I have a button to validate. javascript code is below:

function resultOfValidation(result);
{
    return result;
}

function IsValidDate()
{
    PageMethods.ComplicatedValidation(resultOfValidation);
}

C# code:

[WebMethod]
public static bool ComplicatedValidation()
{
    return true;
} 

but I want to do like

function IsDateTimeAvailable()
{
    var result= PageMethods.ComplicatedValidation();
}

As per my knowledge, it is not possible. If you have any alternative, then please guide me.


Solution

  • Two last parameters for webmethod on client side are success and error callbacks. You can use them. reuturn value is passed to those functions like an argument.