在asp.net(web表单)页面中用jquery调用两个重载web方法
我有两个与属性相同的方法,名为在asp.net(web表单)页面中用jquery调用两个重载web方法,jquery,webforms,webmethod,Jquery,Webforms,Webmethod,我有两个与属性相同的方法,名为[WebMethod],但一个采用参数,另一个是无参数。当我试图通过jquery调用无参数页面方法时,出现错误。我想知道asp.net webform页面中的web方法不可能过载。如果可能的话,我在哪里犯了错误 这是我的示例代码 我在aspx代码隐藏页中定义的两个web方法 [WebMethod] public static string GetFaxUI() { string outputTo
[WebMethod]
,但一个采用参数,另一个是无参数。当我试图通过jquery调用无参数页面方法时,出现错误。我想知道asp.net webform页面中的web方法不可能过载。如果可能的话,我在哪里犯了错误
这是我的示例代码
我在aspx代码隐藏页中定义的两个web方法
[WebMethod]
public static string GetFaxUI()
{
string outputToReturn = "";
//System.Threading.Thread.Sleep(5000);
Page pageHolder = new Page();
BBAReman.UserControls.ucFax ctl = (BBAReman.UserControls.ucFax)pageHolder.LoadControl("~/UserControls/ucFax.ascx");
HtmlForm tempForm = new HtmlForm();
tempForm.Controls.Add(ctl);
pageHolder.Controls.Add(tempForm);
StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);
outputToReturn = output.ToString();
return outputToReturn;
}
[WebMethod]
public static string GetFaxUI(string Country)
{
string outputToReturn = "";
//System.Threading.Thread.Sleep(5000);
Page pageHolder = new Page();
BBAReman.UserControls.ucFax ctl = (BBAReman.UserControls.ucFax)pageHolder.LoadControl("~/UserControls/ucFax.ascx");
ctl.LocalizeUI(Country);
HtmlForm tempForm = new HtmlForm();
tempForm.Controls.Add(ctl);
pageHolder.Controls.Add(tempForm);
StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);
outputToReturn = output.ToString();
return outputToReturn;
}
下面是我通过jquery调用web方法的方法
在相同的代码工作之前,但当我重载方法
GetFaxUI()
时,我得到了错误。请告诉我我犯了什么错误。谢谢您不能重载web方法。你需要给他们起不同的名字。我还建议您创建一个私有函数来完成这项工作,这是由两个web方法调用的,而不是复制所有代码并只添加一行。是否无法通过使用任何属性来重载web方法。不,没有。您只需要两个具有唯一名称的方法。为什么不直接调用第二个方法GetFaxUIByCountry
?
jQuery.ajax({
type: "POST",
url: "FaxUI.aspx/GetFaxUI",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
sHtml = data.d;
sHtml = $(sHtml).find('#content').html();
$sHtml = $(sHtml)
$sHtml.css({ 'display': 'none' }).appendTo('div#dialog');
$.doTimeout(1000, function () {
$(".ui-dialog").animate({
left: (($(window).width() - 346) / 2) + 'px',
top: (($(window).height() - 305) / 2) + 'px',
height: '305px', width: '346px'
}, 200,
function () {
$("#dialog").removeClass("BusyStyles").find('#faxmain').fadeIn(2000);
$("#dialog").css({ height: '26px' });
});
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});