Execute WebMethod (PageMethod) on every minute using using AJAX and JavaScript in ASP.Net

Last Reply 7 months ago By dharmendr

Posted 7 months ago


How to to call web method on every 5 minutes. How can I do this with javascript ?

You are viewing reply posted by: dharmendr 7 months ago.
Posted 7 months ago

Hi Shahzad786,

Use SetInterval function.


<asp:ScriptManager runat="server" EnablePageMethods="true" />
<script type="text/javascript">
    window.onload = function () {
        // Set interval. Currently it is 1 sec.
        setInterval(ShowMessage, 1000);
    function ShowMessage() {
        PageMethods.Message(Success, Failure);
        function Success(result) { alert(result); }
        function Failure(error) { alert(error); }


public static string Message()
    return "Welcome to ASPSnippets.com" + "\n\r" + DateTime.Now;


Public Shared Function Message() As String
    Return "Welcome to ASPSnippets.com" & vbLf & vbCr & DateTime.Now
End Function