参考网页:
http://www.cnblogs.com/top5/archive/2010/08/06/1794087.html
http://bbs.csdn.net/topics/340079072
通过实现接口IPostBackEventHandler的方法,可以实现RaisePostBackEvent(string eventArgument),也就是说可以为客户端空间增加回发功能,这个在某种场景下是很有用的,比如父窗口和子窗口,当然这样的例子很复杂,以后回想起来恐怕也很难记住,这里就说个简单的吧。
首先,前台是这样的。
<div runat="server" id="mydiv">
This is my Div element, but it can be clicked.
</div>
<div runat="server" id="yourdiv">
This is your Div element, but it can be clicked also.
</div>
然后后台代码是这样的。
protected void Page_Load(object sender, EventArgs e)
{
this.mydiv.Attributes["onclick"] = this.Page.ClientScript.GetPostBackEventReference(this, "1234");
this.yourdiv.Attributes["onclick"] = this.Page.ClientScript.GetPostBackEventReference(this, "5678");
}
public void RaisePostBackEvent(string eventArgument)
{
if (eventArgument == "1234")
//this.Page.Title += "Now it is:" + DateTime.Now.ToString();
ExecuteClientRequest(SetLabelA, "", "");
if (eventArgument == "5678")
//this.Page.Title += "Now it is:" + DateTime.Now.ToString();
ExecuteClientRequest(SetLabelB, "", "");
}
之后执行起来,就可以发现通过点击触发服务器端代码。