现在的位置: 首页 > 综合 > 正文

asp.net 2.0 中ICallbackEventHandler的使用(无刷新页面)

2013年06月20日 ⁄ 综合 ⁄ 共 1768字 ⁄ 字号 评论关闭

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
    
<title>Untitled Page</title>
    
<script>
     
function callToServer()
{
    
var param = document.getElementById("txtMessage").value;
    
var context = "";
<% = blientScript %>  
}


function handleResultFromServer(result, context)
{
    document.getElementById(
"txtResult").value = result;
}

    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
<INPUT id="txtMessage" />
<INPUT onclick="callToServer();" type="button" value="Call to Server" id="Button1" />
Result : 
<INPUT id="txtResult" />
    
</div>
    
</form>
</body>
</html>
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 _Default : System .Web.UI .Page , System.Web.UI.ICallbackEventHandler
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
       

    }

   
protected  String blientScript
    
{
        
get
        

            
return this.ClientScript.GetCallbackEventReference(this"param""handleResultFromServer""context");
        }

    }


    
public string RaiseCallbackEvent(string eventArgument)
    
{
        
return "客户端在[" + DateTime.Now.ToString() + "]传送来 [" + eventArgument + "].";
    }



}

原来作者那个无法通过调试....应当这样...
 

return this.ClientScript.GetCallbackEventReference(this"param""handleResultFromServer""context"); //应当这样 在 (asp.net beta2 中)

//参考

http://blog.joycode.com/kaneboy/archive/2004/07/07/26914.aspx

抱歉!评论已关闭.