asp.net 2.0 callbace ajax
可以轻松实现ajax功能,后台异步操作,但要实现页面异步刷新,还需要写javascript来更新页面数据,一般用作从后台取数据等处理,不更新页面,以下是代码
页面代码:
<script type ="text/javascript" >
function serverdel(rtn)
{
document .getElementById ("myload").innerHTML ="ok"
alert(rtn);
}
</script>
<a href="#" onclick='javascript:mydel(<%#Eval("seg_id") %>)'>delete</a>
<span id="myload"></span>
string ICallbackEventHandler.GetCallbackResult()
{
return "操作成功!";
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
System.Threading.Thread.Sleep(500);
obj.Delsegment(Int32.Parse(eventArgument));
BindGrid();
}
![](/Images/OutliningIndicators/None.gif)
protected void Page_PreRender(object sender, EventArgs e)
{
ClientScriptManager cs = Page.ClientScript;
string func = cs.GetCallbackEventReference(this,"arg","serverdel",null);
string strback = "function mydel(arg) { "+func+";document .getElementById ('myload').innerHTML ='正在处理
'}";
cs.RegisterClientScriptBlock(this.GetType(),"back",strback,true);
}
页面代码:
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
<a href="#" onclick='javascript:mydel(<%#Eval("seg_id") %>)'>delete</a>
<span id="myload"></span>
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)