首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

遇到个辣手的有关问题, 为什么不能够使用Asp.net 2.0的客户端回调功能

2012-01-10 
遇到个辣手的问题, 为什么不能够使用Asp.net 2.0的客户端回调功能代码如下:1.前台htmlxmlns http://www

遇到个辣手的问题, 为什么不能够使用Asp.net 2.0的客户端回调功能
代码如下:
1.   前台
<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title> Client-Side   Callback </title>
       
        <script   type= "text/javascript ">
                function   GetNumber()
                {                        
                      UseCallBack( 'abc ',   'context ');                      
                }
                function   GetRandomNumberFromServer(result,   context)
                {
                        document.forms[0].TextBox1.value   =   result;
                }
        </script>


</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>                
                <input   id= "Button1 "   type= "button "   value= "button "   onclick= "GetNumber() "   />
                <br   />
                <br   />
                <asp:TextBox   ID= "TextBox1 "   runat= "server "> </asp:TextBox> </div>
        </form>
</body>
</html>

2.   后台
using   System;
using   System.Data;
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   Default2   :   System.Web.UI.Page,   ICallbackEventHandler
{
        private   string   _callbackResult   =   null;
       
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                string   cbReference   =   Page.ClientScript.GetCallbackEventReference(this,   "arg ",   "GetRandomNumberFromServer ",   "context ");
                string   cbScript   =   "function   UseCallBack(arg,   context) "   +   "{ "   +   cbReference   +   "; "   +   "} ";
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(),   "useCallBack ",   cbScript,   true);


        }

        public   void   RaiseCallbackEvent(string   eventArg)
        {
                Random   rnd   =   new   Random();
                _callbackResult   =   rnd.Next(100).ToString();
                return;
        }        

        public   string   GetCallbackResult()              
        {
                return   _callbackResult;
        }
}


运行环境:   vs2005   pro
另外,   会不会是VS版本的问题???

希望尽快得到解答.
谢谢!




[解决办法]
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "ClientCallback.aspx.cs " Inherits= "ClientCallback " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN " "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd ">

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head id= "Head1 " runat= "server ">
<script type= "text/javascript ">
function LookUpStock()
{
var lb = document.forms[0].ListBox1;
var product = lb.options[lb.selectedIndex].text
CallServer(product, " ");
}

function ReceiveServerData(rValue)
{
Results.innerText = rValue;
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:ListBox ID= "ListBox1 " Runat= "server "> </asp:ListBox>
<br />
<br />
<button onclick= "LookUpStock() "> Look Up Stock </button>
<br />
<br />
Items in stock: <span ID= "Results "> </span>
<br />
</div>
</form>
</body>
</html>

[解决办法]
ding
[解决办法]
什么叫回调功能

热点排行