Question

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.

Était-ce utile?

La 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.

Autres conseils

More...

function GetValue() 
{ 
    return PageMethods.GetValueFromServer( 
     function(result) 
       { 
          // The result that is returned from server 
          //Now do what ever you would like to do. 
       }
    ); 
}

You can try something like this:

           var secuencias = new String;
           jQuery("#add_note").click(function() {

                                                    $.ajax({
                                                    type: "POST",
                                                    url: '<%= ResolveUrl("~/Paginas/EscuchadorAlertas.aspx/ConsultarAlertas") %>',
                                                    data: "{}",
                                                    contentType: "application/json; charset=utf-8",
                                                    dataType: "json",
                                                    async: false,
                                                    success: function(msg) {
                                                        secuencias = msg.d;
                                                    },
                                                    error: function() {
                                                        alert("error");
                                                   }
                                                   });
                                                });

As you can see inside the variable secuencia is stored the value of de function ConsultarAlertas which is a PageMethods function that just return a String.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top