ICallbackEventHandler asp.net页面异步回发

ICallbackEventHandler 接口:用于指示控件可以作为服务器的回调事件的目标。

asp.net页面通实现该接口可以实现无刷新回发。

后台:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public  partial  class Default2 : System.Web.UI.Page, ICallbackEventHandler
{
     private  string ttt;
     protected  void Page_Load( object sender, EventArgs e)
    {
        ClientScriptManager csm =  this.ClientScript;
         string t = csm.GetCallbackEventReference( this" arg "" test "" context "); // 生成客户端的回发函数,注意此处的arg,context.要与下行中的注册js函数的参数相同
        csm.RegisterStartupScript( this.GetType(),  " x "" function gml(arg,context){ " + t +  " } "true);
    }

     public  string GetCallbackResult()
    {
         return ttt;
    }

     public  void RaiseCallbackEvent( string eventArgument)
    {
        ttt =  " OK " + eventArgument;
    }
}

 

前台代码:

< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head  runat ="server" >
     < title ></ title >
     < script  type ="text/javascript" >
     
function  test(re,context) {
         alert(re);
       alert(context);
     }
     
function  clicktest() {
         gml(
" txt " , " x " );
     }

    
</ script >
     < style  type ="text/css" >
     #t    
     
{
         position
: absolute ;
         width
: 500px ;
         height
: 300px ;
         background-color
: blue ;
         
}
    
</ style >
</ head >
< body >
     < form  id ="form1"  runat ="server" >
    
     </ form >
     < div  id ="t" >
         < a   onclick ="clicktest()" >about </ a >
     </ div >
</ body >
</ html >

转载于:https://www.cnblogs.com/guolihao/archive/2012/07/30/2615312.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值