从输出超过100条记录的javascript函数调用ASP.NET pagemethod时出错

时间:2016-03-14 23:55:41

标签: javascript c# asp.net pagemethods

我有一个调用asp.net pagemethod的javascript函数。它工作正常,直到今天我注意到它偶尔会停止工作。经过大量测试后,我意识到当pagemethod返回100行或更多行时,javascript函数会出错。我目前正在使用Stringbuilder来追加记录,然后我使用javascript函数来更新页面上的控件(在这种情况下它只是一个asp:标签)。我的目标是能够单击标题按钮按列排序而无需重新加载页面。现在,如果我从代码隐藏中调用pagemethod(参见示例1),那么就没有问题所以它与javascript函数有关,但我无法弄清楚我做错了什么。 javascript是否对字符串施加了某种限制?这是代码。任何帮助将不胜感激:

示例1:

activeLbl.Text = getTest();
//This works as expected

ASP.NET Codebehind(C#)

[WebMethod]
public static string getTest()
{
    string theString = "";
    StringBuilder sb2 = new StringBuilder(theString);

    string sortField = "barcode";
    List<Asset> list = new List<Asset>();
    list = AssetManager.getActiveInventoryByOwner("john.doe", "id", "DESC");
    //function takes the following parameters: userid, sort expression, sort direction

     sb2.Append("<table width=100%><tr><thead><th><input type=button value=ID onclick=\"CallSortActiveInventory('" + sortField + "');return false\";></th><th>Serial No.</th><th>Make/Model</th><th>Current User</th><th>Type</th></thead></tr>");
    foreach (Asset item in list)
    {
     sb2.Append("<tr><td style=width:15%;>" + item.Id + "</td><td style=width:20%; text-align:center;>" + item.SerialNumber + "</td><td style=text-align:center;width:15%;>" + item.MakeModel + "</td><td style=width:15%;text-align:center;></td><td style=text-align:center;>" + item.PropertyType + "</td></tr>");
    }
    sb2.Append("</table>");
    theString = sb2.ToString();
    return sb2.ToString();

}

JavaScript函数

function CallSortActiveInventory() {
    PageMethods.getTest(CallSortActiveInventorySuccess, CallPageMethodFailed);
}

function CallSortActiveInventorySuccess(result, userContext, methodName) {
    document.getElementById("<%=activeLbl.ClientID%>").innerHTML = result;
}

function CallPageMethodFailed(error, userContext, methodName) {
    alert("An error occurred")
}

0 个答案:

没有答案