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;
}
}
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 >
< 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 >