 悬赏园豆:5
                [已解决问题] 
            
                    解决于 2012-07-10 12:45
                悬赏园豆:5
                [已解决问题] 
            
                    解决于 2012-07-10 12:45 
                 
        <script type="text/javascript" language="javascript">
        function btnAysn_Click() {
        var text=document.getElementById('TextBox1').value;
        <%= ClientScript.GetCallbackEventReference(this, text, "GetResultFromServer", "")%>
        }
        function GetResultFromServer(value, context)
        {
            alert( value);
        }
    </script>
运行的结果是
Compiler Error Message: CS0103: The name 'text' does not exist in the current context
Source Error:
| Line 9:          function btnAysn_Click() {
Line 10:         var text=document.getElementById('TextBox1').value;
Line 11:         <%= ClientScript.GetCallbackEventReference(this, text, "GetResultFromServer", "")%>
Line 12:         }
Line 13:         function GetResultFromServer(value, context) | 
请问应该怎么改
我觉得你首先要搞清楚为什么出这个错。
<%= %>中的代码会在页面呈现的时候在服务器端执行,从错误提示不难看出变量“text”找不到,而text变量是javascript变量。
所以你的问题应该是在javascript中执行后台代码,也就是C#代码。
请点击,发现问题根本原因,然后解决问题。
哈哈,我也是才发现的。。 感觉自己真的2B了
给你看看我的代码吧
public partial class Work_RiZhi : BasePage, ICallbackEventHandler { protected DateTime date; string returnvalue; protected void Page_Load(object sender, System.EventArgs e) { string CallbackScript = @" function CallServer(arg) { " + ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", null) + @"; } "; ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", CallbackScript, true); } public void RaiseCallbackEvent(string eventArgument) { if (eventArgument != string.Empty) { //todo } } public string GetCallbackResult() { return returnvalue; }
  function ReceiveServerData(ReturnValue) {
             if (ReturnValue == "") {
                 alert("保存失败,请重试或检查时间"); return false;
             }
}
前台调用 CallServer()即可
请尝试把这段JS 放到form标签范围之内
http://www.huankazhongxin.com
游戏点卡换卡中心为大家提供换充值卡互换平台,为需要一卡通互换用户提供方便、快捷的兑换服务轻松搞定!
嗯。
服务器端和客户端要区分开,概念要搞清楚。js代码放哪都是不行的。
服务器端代码能直接访问 客户端代码,那就神奇了。
哥,你得去看下ASP.NET 原生的AJAX