Reputation: 186
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.
Upvotes: 4
Views: 8852
Reputation: 11
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.
Upvotes: 0
Reputation: 176896
function GetValue()
{
return PageMethods.GetValueFromServer(
function(result)
{
// The result that is returned from server
//Now do what ever you would like to do.
}
);
}
Upvotes: 3
Reputation: 12815
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.
Upvotes: 4