两个dropdownlist控件,一个发生onchange事件后,使用回调函数更新另外一个dropdownlist.测试结果为,数据返回并加载到dropdownlist,但出现脚本错误"_pendingcallbacks[..].async为空或不是对象”。百思不能解决,请高手指教。谢谢
<%@ Page Language="C#" Theme="SkinFile" AutoEventWireup="true" CodeFile="Sys_ConItemTrace.aspx.cs" Inherits="Sysmanager_Sys_ConItemTrace" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
    function UpMethod()
    {   //回调,根据选择的合同类型
        var lb=document.getElementById("DDLConKind");        
        var product = lb.options[lb.selectedIndex].value;
        CallServer(product, "");
    }
    
    function ReceiveServerData(rValue,context)
    { //得到回调返回的数据,有两部分组成1、用“|"分开的描述和代码2.用“;”区分的文本加到listbox
        var LbMethod=document.getElementById("DDLMethod");
        LbMethod.options.length=0;        
        var CdTxt=rValue.split("|");        
        var LsTxt=CdTxt[0].split(";");
        var LsValue=CdTxt[1].split(";");
        var NewOpt=new Array();       
             
        for(i=0;i<LsValue.length-1;i++)
        {      
           
            NewOpt[i] = document.createElement("OPTION");          
            NewOpt[i].value =LsValue[i];             
            NewOpt[i].text=LsTxt[i];       
             LbMethod.options.add(NewOpt[i]);
        }
        var SelOpt=document.createElement("OPTION");
        SelOpt.text="--请选择--";
        LbMethod.options.add(SelOpt,0);
        LbMethod.options[0].selected=true;
       
    }
  </script></head>
<body bgcolor="#f0f0f0">
    <form id="form1" runat="server">
    <div align=center >
    <br />      
    合同类型:
<asp:DropDownList ID="DDLConKind" runat="server" Width="139px">
          </asp:DropDownList>采购方法:
      <asp:DropDownList ID="DDLMethod" runat="server" Width="199px" >
          </asp:DropDownList>      
   
      </div>
    </form>
</body>
</html>c#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Sysmanager_Sys_ConItemTrace : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
 
{
    public string ReturnValue; //返回给回调的值
    public CrespObj.CommClass MyCls = new CrespObj.CommClass(); //通用类
    protected ClientScriptManager CSpt;
   
    protected void Page_Load(object sender, EventArgs e)
    {
        CSpt = Page.ClientScript;
     
        DDLConKind.Attributes.Add("onchange","UpMethod()"); //给下拉框增加客户端事件
        
        String cbReference =
            Page.ClientScript.GetCallbackEventReference(this,"arg", "ReceiveServerData", "context");
        String callbackScript;
        callbackScript = "function CallServer(arg, context)" +
            "{ " + cbReference + "} ;";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
            "CallServer", callbackScript, true);
        
        if (!IsPostBack)
        {
            SetKindDDl(); //初始合同类型下来框
            DDLConKind.Items[0].Selected = true;
           
        }
    }
   public void RaiseCallbackEvent(String eventArgs)
    {
          string StrSql = "SELECT Method_App_Abb,Method_App_CN FROM Method_Applied where Contract_kind='" + eventArgs + "'";
        string RtAbb="";
        DataSet MethDs = MyCls.Getds(StrSql);
        foreach (DataRow DrV in MethDs.Tables[0].Rows)
        {
            ReturnValue += (DrV["Method_App_CN"].ToString() + ";"); //返回描述
            RtAbb += (DrV["Method_App_Abb"].ToString() + ";"); //返回代码
        }
        ReturnValue = ReturnValue + "|" + RtAbb;
             
    }
    public string GetCallbackResult()
    {
        return this.ReturnValue;
    }

解决方案 »

  1.   

    找到问题了,原来js脚本中的变量i和.net自动生成的代码中的变量重复定义。把i改成其他命名就ok了
      

  2.   

    我也碰到跟楼主一样的问题,但是一直没解决。麻烦知道的说一下好么。。我邮箱:[email protected]如果有解决方案的发到我邮箱吧。。大家互相学习,谢谢了
      

  3.   

    Append this to the bottom of your page (this is what Microsoft should have put in their code in the first place:function WebForm_CallbackComplete() {
        for (var i = 0; i < __pendingCallbacks.length; i++) {
            var callbackObject = __pendingCallbacks[i];
            if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4)) {
                WebForm_ExecuteCallback(callbackObject);
                if (__pendingCallbacks[i] && !__pendingCallbacks[i].async) {
                    __synchronousCallBackIndex = -1;
                }
                __pendingCallbacks[i] = null;
                var callbackFrameID = "__CALLBACKFRAME" + i;
                var xmlRequestFrame = document.getElementById(callbackFrameID);
                if (xmlRequestFrame) {
                    xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
                }
            }
        }

    绝对可行,把这个函数放到页的底部!