写了,居然就报错了。

解决方案 »

  1.   

    看来除了ajax这些方法就比较难了
      

  2.   

    改编msdn的例子:
    public partial class wc : System.Web.UI.UserControl, ICallbackEventHandler
    {
        private string str;
        protected void Page_Load(object sender, EventArgs e)
        {
            String cbReference =
                this.Page.ClientScript.GetCallbackEventReference(this,
                "arg", "ReceiveServerData", "context");
            String callbackScript;
            callbackScript = "function CallServer(arg, context)" +
                "{ " + cbReference + "} ;";
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
                "CallServer", callbackScript, true);
        }    protected void Button2_Click(object sender, EventArgs e)
        {    }    string ICallbackEventHandler.GetCallbackResult()
        {
            return str+"xxx";
        }    void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
        {
            str = eventArgument;
        }
    }<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wc.ascx.cs" Inherits="wc" %>  <script type="text/javascript">
        function LookUpStock()
        {
            var product = 'ppp'; 
            CallServer(product, "");
        }
        
        function ReceiveServerData(rValue)
        {
            Results.innerText = rValue;
        }
      </script><table>
        <tr>
            <td>
          <button onclick="LookUpStock()">Look Up Stock</button>
          <br />
          <br />
          Items in stock: <span ID="Results"></span>
          <br />        </td>
        </tr>
    </table>
      

  3.   

    你运行程序了么?如果在用户控件用会提示你this.Page.ClientScript.GetCallbackEventReference无效。必须要获取最顶层的page对象,我是这么想的
    -----------------------
    谁能从你的问题中看出你到底有什么问题呀?看不出来你到底做了什么。如果你在用户控件中使用不行,那么你在页面中使用客户端回调成功了吗?在自定义控件中成功了吗?成功的和不成功的有什么区别?你到底怎么不成功?
    --------------------------
    不成功!就是提示的this.Page.ClientScript.GetCallbackEventReference无效的
      

  4.   

    运行了的说,没问题(至少在我这里)。建议找找其他问题,用户控件肯定可以继承ICallbackEventHandler
      

  5.   

    原来区别是有的
    page页面前台可以这样写
      <%=ClientScript.GetCallbackEventReference(this,"arg","ReceiveServerData", null)%>
    但是用户控件里必须写
      <%=Page.ClientScript.GetCallbackEventReference(this,"arg","ReceiveServerData", null)%>
    结分