returning value from page method in asp.net

Sanjay Gupta picture Sanjay Gupta · Sep 11, 2012 · Viewed 8k times · Source

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.

Answer

Viktor S. picture Viktor S. · Sep 11, 2012

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.