c# 通过ICallbackEventHandler 实现页面无刷新
2011-08-14 22:43
274 查看
创建服务器回调方法
在服务器代码中,必须创建一个实现RaiseCallbackEvent方法的方法和一个实现GetCallbackResult方法的方法。RaiseCallbackEvent方法接受单个字符串参数,而不是通常用于事件处理程序的常见的两个参数。该方法的部分内容可能与下面的代码示例类似。publicvoidRaiseCallbackEvent(StringeventArgument)
{
}
GetCallbackResult不接受参数并返回一个字符串。该方法的部分内容可能与下面的代码示例类
publicstringGetCallbackResult()
{
returnaStringValue;
}
Aspx:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="WebTest.WebForm1"%>
<%@ImportNamespace="System.Web.UI"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scripttype="text/jscript">
functionCallServer(inputcontrol,context)
{
//回调还没有处理完全时其预先加载的显示值
context.innerHTML="加载中...";
//这里的arg传递到后台RaiseCallbackEvent(stringeventArgument)方法中去
arg=inputcontrol.value;
//获取一个对客户端函数的引用调用该函数时将启动一个对服务器端事件的客户端回调
//各参数含义:
//this指当前页面
//arg客户端传递给服务端RaiseCallbackEvent的值
//ReceiveServerData客户端的一个js函数,服务器会返回值传递给这个函数,做为这个函数的参数。
//context脚本的结果传回客户端事件处理程序
<%=ClientScript.GetCallbackEventReference(this,"arg","ReceiveServerData","context")%>
}
functionReceiveServerData(result,context)
{
context.innerHTML=result;
}
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title>无标题页</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<inputid="Text1"type="text"/>
<inputid="Button1"type="button"value="button"onclick="CallServer(Text1,Label1);"/>
</div>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</form>
</body>
</html>
Aspx.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
namespaceWebTest
{
publicpartialclassWebForm1:System.Web.UI.Page,ICallbackEventHandler
{
stringtestvalue="";
protectedvoidPage_Load(objectsender,EventArgse)
{
}
#regionICallbackEventHandler成员
publicstringGetCallbackResult()
{
returntestvalue;
}
publicvoidRaiseCallbackEvent(stringeventArgument)
{
testvalue=eventArgument+"1";
}
#endregion
}
}
相关文章推荐
- c# 通过ICallbackEventHandler 实现页面“无刷新”
- c#通过ICallbackEventHandler接口实现回调
- Asp.Net2.0页面通过ICallbackEventHandler接口实现Ajax
- 六步使用ICallbackEventHandler实现无刷新回调
- 深入体验JavaWeb开发内幕之Response对象操作实例之通过Response实现重定向和刷新跳转并跳转页面
- 如何在无刷新页面的情况下实现客户端回调实例(C#)—MSDN学习笔记
- ASP.NET无刷新客户端回调(通过实现ICallbackEventHandler接口)
- 六步使用ICallbackEventHandler实现无刷新回调
- 使用ICallbackEventHandler实现无刷新验证用户名是否存在
- C# Winform 通过FlowLayoutPanel及自定义的编辑控件,实现快速构建C/S版的编辑表单页面
- 如何通过JQ,Ajax来实现返回到上一个页面并进行刷新
- 六步使用ICallbackEventHandler实现无刷新回调
- (Dotnet2.0)ICallbackEventHandler实现无刷新操作
- 【WINFORM】C#中不通过浏览页面直接登入博客园的实现
- 六步使用ICallbackEventHandler实现无刷新回调
- 六步使用ICallbackEventHandler实现无刷新回调
- 六步使用ICallbackEventHandler实现无刷新回调
- 利用ICallbackEventHandler实现dropdownlist的无刷新多级联动
- 六步使用ICallbackEventHandler实现无刷新回调
- 六步使用ICallbackEventHandler实现无刷新回调