ASP.net 2.0的回调是否有中文问题,以下的一个无关的DropDownList的Value值发生变化。<asp:DropDownList ID="DropDownList2" runat="server" 
AppendDataBoundItems="True"> 
<asp:ListItem Value="aa">- Select Product -</asp:ListItem> 
</asp:DropDownList> 
此语句下工作正常
变成
<asp:DropDownList ID="DropDownList2" runat="server" 
AppendDataBoundItems="True"> 
<asp:ListItem Value="好">- Select Product -</asp:ListItem> 
</asp:DropDownList> 
就工作不正常了,Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");根本就不执行回调,why?以下附部分源码。各位大虾看看,是不是微软VS2005的bug?

解决方案 »

  1.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="callclass.aspx.cs" Inherits="WLBill_callclass" CodePage="936"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> <script type="text/javascript"> 
    function CallServer(arg, context) 

    context.innerHTML = "Loading"; 
    <%= callback %>; 
    } function ReceiveServerData(result, context) 

    context.innerHTML = result; 

    function RefreshBind()
    {
    //alert("ok111");
    //  opener.Form1.TFaZhan.value="tt";
    //  opener.location="mobile_send.aspx";
         Form1.Brefresh.click();
    //  window.close();
    }
    function CRefresh(CNO,ctype)
    {
    //alert("ok111");
    switch(ctype)
    {
      case "TY" :   Form1.TTYCNO.value=CNO;
                    Form1.Btyok.click();
                     break;
      case "SH" :   Form1.TSHCNO.value=CNO;
                    Form1.Bshok.click();
                     break;
      case "FK" :   Form1.TFKCNO.value=CNO;
                    Form1.Bfkok.click();
                     break;
      default: break;
    } }
    </script><head> 
    <title>Callback</title> 
    </head> 
    <body> 
    <form id="form1" runat="server"> 
    <div> 
    <div id="_div1" runat="server"> 
    <asp:DropDownList ID="ddlCategory" runat="server"  AppendDataBoundItems="True"> 
    <asp:ListItem Value="">- Select Category -</asp:ListItem> 
    <asp:ListItem Value="aa">- Select Category -</asp:ListItem> 
    <asp:ListItem Value="bb">- Select Category -</asp:ListItem> 
    </asp:DropDownList> 
    <span id="_span1"> 
    <asp:DropDownList ID="ddlProduct" runat="server" 
    AppendDataBoundItems="True" Visible=false> 
    <asp:ListItem Value="好">- Select Product -</asp:ListItem> 
    </asp:DropDownList> 
    </span><span id="_span2"> 
    <asp:Button ID="btnBuy" runat="server" Text="Buy" Enabled="false" OnClick="btnBuy_Click" /> 
    <br /> 
    </span> 
    </div> 
    <asp:Label ID="Label2" runat="server"></asp:Label> 
    </div> 
    <div>
    <asp:DropDownList ID="DropDownList2" runat="server" 
    AppendDataBoundItems="True"> 
    <asp:ListItem Value="aa">- Select Product -</asp:ListItem> 
    </asp:DropDownList> 
    </div>
    <asp:Label ID="Label1" runat="server">好</asp:Label> 
    </form> 
    </body> 
    </html> 
    CS文件:
     public string callback = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            ddlCategory.Attributes.Add("onchange", "CallServer('FillProduct|'+this.value+'|heqian',_span1)");
            ddlProduct.Attributes.Add("onchange", "CallServer('ShowBuy|'+this.value,_span2)");
            callback=Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
            if (!Page.IsPostBack)
            {
              //  BindDataDrop();
            }
        }
     #region ICallbackEventHandler Members        public string GetCallbackResult()
            {
                string[] parts = _callbackEventArgument.Split('|');
                object[] args = null;
                string result = "";            if (parts.Length > 1)
                {
                    args = new object[parts.Length - 1];
                    Array.Copy(parts, 1, args, 0, args.Length);
                }            MethodInfo method = this.GetType().GetMethod(parts[0]);            if (method != null)
                {
                    result = (string)method.Invoke(this, args);
                }            return result;
            }        public void RaiseCallbackEvent(string eventArgument)
            {
                // _eventArgument = eventArgument;
                _callbackEventArgument = eventArgument;
            }        void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
            {
                this.RaiseCallbackEvent(eventArgument);
            }        string ICallbackEventHandler.GetCallbackResult()
            {
                return this.GetCallbackResult();
            }        #endregion
            public string RenderControl(Control control)
            {
                StringWriter writer1 = new StringWriter(CultureInfo.InvariantCulture);
                HtmlTextWriter writer2 = new HtmlTextWriter(writer1);            control.RenderControl(writer2);
                writer2.Flush();
                writer2.Close();            return writer1.ToString();
            }
        public string FillProduct(string categoryID, string tmp)
        {
            // ddlCategory.SelectedValue = categoryID;
            //ddlProduct.DataBind();
            BindUsers(categoryID, tmp);
            ddlProduct.Visible = true;
            return RenderControl(ddlProduct);
        }    public string ShowBuy(string ProductID)
        {
            btnBuy.Enabled = !string.IsNullOrEmpty(ProductID);        return RenderControl(btnBuy);
        }
        protected void btnBuy_Click(object sender, EventArgs e)
        {
            _div1.Visible = false;
            Label1.Text = "Buy: " + Request.Form[ddlProduct.UniqueID];
        }