C#在System.web.services.WebMethod中传递变量
一般来说,在AJAX和javascript方面,我是个垃圾 我有一个WebMethod: [System.Web.Services.WebMethod] 公共静态字符串转储客户端() {} 我在js文件中有以下代码:C#在System.web.services.WebMethod中传递变量,c#,webmethod,C#,Webmethod,一般来说,在AJAX和javascript方面,我是个垃圾 我有一个WebMethod: [System.Web.Services.WebMethod] 公共静态字符串转储客户端() {} 我在js文件中有以下代码: mainScreen.DumpClients = function() { $('#runclientdumpbtn').attr("disabled", "true"); mainScreen.clientDiv.innerHTML = ""; $("#l
mainScreen.DumpClients = function() {
$('#runclientdumpbtn').attr("disabled", "true");
mainScreen.clientDiv.innerHTML = "";
$("#loadingimageclientdump").show();
PageMethods.DumpClients(mainScreen.DumpClientsCallback, mainScreen.DumpClientsFailed);
}
mainScreen.DumpClientsCallback = function(result) {
if (result) {
$("#loadingimageclientdump").hide();
mainScreen.clientDiv.innerHTML = result;
$('#runclientdumpbtn').removeAttr("disabled");
}
};
mainScreen.DumpClientsFailed = function(error, userContext, methodName) {
if (error) {
// TODO: add your error handling
$("#loadingimageclientdump").hide();
mainScreen.clientDiv.innerHTML = error.get_message();
$('#runclientdumpbtn').removeAttr("disabled");
}
};
Sys.Application.add_load(applicationLoadHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
在我需要从页面中访问dropdownlist之前,这一切都很好(我承认我根本不完全理解这一点)。由于它是一个静态方法,我无法直接获取它,因此我认为可以通过webmethod将值传递回
小问题是我不知道怎么做。我一直在谷歌上搜索,但进展不快。我正在阅读一本JQuery的书,了解更多的基础知识,但目前这远远超出了我的理解范围
我感谢所有的帮助和建议,很抱歉我可能问了一个有点愚蠢的问题。因此我决定我完全走错了方向,并寻找更好的方法调用该方法,并找到了以下解决方案:
$("#runclientdumpbtn").click(function() {
var selectedreporttype = $("#<%= dropdownpageID %>").val();
$.ajax({
type: "POST",
url: "default.aspx/ExtractContacts",
data: "{outputtype:'" + selectedreporttype + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnContactSuccess,
failure: OnContactFailure,
error: OnContactFailure
});
startContact();
});
[WebMethod()]
public static string ExtractContacts(string outputtype)
{
}
$(“#runclientdumpbtn”)。单击(函数(){
var selectedreporttype=$(“#”)val();
$.ajax({
类型:“POST”,
url:“default.aspx/ExtractContacts”,
数据:“{outputtype:'”+selectedreporttype+“}”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:接触成功,
失败:OnContactFailure,
错误:OnContactFailure
});
startContact();
});
[WebMethod()]
公共静态字符串提取联系人(字符串输出类型)
{
}
希望这对其他人有帮助