Ajax技术三种实现方式之asp.net2.0 callback篇 (四)
2011-04-15 12:01
447 查看
View Code
一、 Asp.net2.0的形式:CallBack 1、CallBack.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CallBack.aspx.cs" Inherits="AJAX.CallBack" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <mce:script language="javascript" type="text/javascript"><!-- function ReceiveServerData(arg, context) { document.getElementById ("msg_display").innerHTML=arg; } function CallTheServer(arg,context) { <%=ClientScript.GetCallbackEventReference(this,"arg", "ReceiveServerData", "context") %> } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div> <input id="testmsg" type="text" value="Hello,World!" style="width: 214px"><br /> <input type="button" value="單擊這個" onclick="CallTheServer(document.getElementById('testmsg').value)" /> 提交给服务器的CallBack <div id="msg_display" style="background: yellow; font-weight: bold; font-size: 13px" mce_style="background: yellow; font-weight: bold; font-size: 13px"> 从服务器返回的信息在这里显示...</div> </div> </form> </body> </html> 2、CallBack.aspx.cs using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Text; namespace AJAX { public partial class CallBack : System.Web.UI.Page,ICallbackEventHandler { protected void Page_Load(object sender, EventArgs e) { } // Summary: // Returns the results of a callback event that targets a control. // // Returns: // The result of the callback. StringBuilder builder = new StringBuilder(); public string GetCallbackResult() { return builder.ToString(); } // // Summary: // Processes a callback event that targets a control. // // Parameters: // eventArgument: // A string that represents an event argument to pass to the event handler. public void RaiseCallbackEvent(string eventArgument) { builder.Append("服务器callback得到了您输入的信息:" + eventArgument + "<br/>您的IP地址是:"); builder.Append(Request.UserHostAddress); builder.Append("<br/>当前服务器的时间:"); builder.Append(DateTime.Now.ToLocalTime()); } } }
相关文章推荐
- Ajax 技术三种实现方式之xmlhttp+webform篇 (二)
- 三种实现Ajax的方式
- struts2 --- ajax的三种实现方式
- AJAX实现文件下载的三种方式
- 利用jquery实现Ajax技术,post方式传值中文乱码问题的解决办法。
- JSP中分页技术的实现(jstl,servlet,javabean三种不同实现方式)
- jquery实现Ajax请求的三种方式
- ajax的三种实现方式
- ASP.NET MVC2中三种ajax实现方式-原始JavaScript
- 一起谈.NET技术,Asp.net mvc 2中使用Ajax的三种方式
- ASP.NET MVC2中三种ajax实现方式-使用Jquery
- Android实现XML解析技术的三种方式
- ASP.NET MVC2中三种ajax实现方式-使用AjaxHelper
- JAVAweb开发技术-------(六)技术点-定时任务实现的三种方式
- 有了html页面,进行二次显示,通过html、JavaScript、jQuery的ajax三种技术,我可以实现任何界面效果
- 实现XML解析的几种技术(SAX、Pull、Dom三种方式)
- ASP.NET2.0(VS2008) Ajax实现的几种方式
- 三种ASP.Net网站AJAX实现方式
- 用Ajax技术和dwr框架两种方式实现下拉列表的级联效果
- ajax的三种实现方式及解释json数据