我相信你必须为此使用AJAX。看看这里:https://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx
ReloadData会在你的代码一个WebMethod后面,将是这个样子:
[System.Web.Services.WebMethod]
public void ReloadData()
{
//here is the code
}
然后从客户端,你会做这样的事情:
function GetData() {
$.ajax({
type: "POST",
url: "CS.aspx/ReloadData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function(response) {
alert(response.d);
}
});
}
CS.aspx
是您的网页的名称。
继续从您的评论下面;如果你不想使用jQuery那么你的Javascript代码会是这个样子:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'CS.aspx/ReloadData');
xhr.onload = function() {
if (xhr.status === 200) {
alert('Successful');
}
else {
alert('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
[Pagemethods在asp.net]的可能的复制(https://stackoverflow.com/questions/4313532/pagemethods-in -asp-net) – EdSF
nope这不是重复的,因为这里调用了javascript,但不会在服务器端方法 –
再次阅读。当天结束时,您正在使用客户端脚本向某个服务器资源发出请求。“Web Forms”具有'PageMethods'作为您可以使用的_option_,并且需要一些设置。 – EdSF