I have jQuery plugin – progress bar. How to invoke server side method on success? The code is below:
(Everything works fine)
$("#<%=this.btnGetData.ClientID%>").click(
function () {
intervalID = setInterval(updateProgress, 100);
$.ajax({
type: "POST",
url: "ProgressBar.aspx/ExecuteImport",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (msg)
{
//HERE should be invoke
}
});
return false;
}
);
As we’ve established this in WebForms then you can use an ASP.NET AJAX callback to a web method placed in your aspx file.
First, create your server side method in C# (or .NET language of choice) and annotate it with the ScriptMethod and WebMethod attributes, like so:
Then in your aspx file you need to add a ScriptManager with PageMethods enabled:
Then call it from your jQuery success event:
I’m basing this on my Hidden Features of ASP.NET answer here (which is not jQuery specific). However, for more details about using jQuery with WebMethods have a read of Using jQuery to directly call ASP.NET AJAX page methods.