Microsoft のすぐに使用できるUpdatePanel と Timer を使用できます。
Microsoft ボックスの内容が気に入らず、jQuery/javascript を使用したい場合は、一定の間隔で (window.setInterval
メソッドを使用して) AJAX 要求をASP.NET PageMethodに送信できます(この場合、基本的には少し自分自身を与える必要があります)。 jQuery のドキュメントやチュートリアルを読んだり、少しコードを書いたりするのは面倒です)。
したがって、ASP.NET PageMethod は次のようになります。
[WebMethod]
public static int Approved()
{
return (from obj in db.RequestList
where obj.IsApproved == "Approved"
select obj).Count();
}
次に、この PageMethod を 1 分ごとに AJAX リクエストで叩きます。
window.setInterval(function() {
$.ajax({
url: '/foo.aspx/Approved',
type: 'POST',
contentType: 'application/json',
data: '{ }',
success: function(result) {
var count = result.d;
// TODO: do something with the count returned by the server
// like assigning it to a label or something:
$('#someLabelId').html(count);
}
});
}, 60 * 1000);