我有一个 javascript 函数,它构建一个字符串,然后将字符串发送到 c# 代码隐藏以使用。问题是,PageMethods.Method 永远不会被调用。
相关代码:
页面:
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" EnablePartialRendering="true"
runat="server" />
<script type="text/javascript">
function makeString() {
debugger
var a = document.getElementById("ddlRptYear").value + "_";
var b = document.getElementById("ddlRptType").value + "_";
var c = document.getElementById("ddlGeography").value + "_";
var d = "";
var e = "";
var x = document.getElementById("ddlTouchPoint");
var y = document.getElementById("ddlAOR");
if (x.disabled == false) {
d = x.value + "_";
}
if (y.disabled == false) {
e = y.value;
}
var pptString = a + b + c + d + e + ".ppt";
PageMethods.GetPPTString(pptString, onSuccess, onFail);
}
代码隐藏:
[System.Web.Services.WebMethod]
public static void GetPPTString(string pptString)
{
if ((pptString == "") || (pptString == null))
{
throw new Exception("Error: No String Sent.");
}
else
{
throw new Exception(pptString);
}
}