Ajax技术三种实现方式之asp.net2.0 callback篇 (四)

ContractedBlock.gif ExpandedBlockStart.gif View Code
 
   
1 一、 Asp.net2.0的形式:CallBack
2 1 、CallBack.aspx
3 <% @ Page Language = " C# " AutoEventWireup = " true " CodeBehind = " CallBack.aspx.cs " Inherits = " AJAX.CallBack " %>
4
5 <! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
6
7 < html xmlns = " http://www.w3.org/1999/xhtml " >
8 < head runat = " server " >
9 < title > Untitled Page </ title >
10 < mce:script language = " javascript " type = " text/javascript " ><!--
11 function ReceiveServerData(arg, context)
12 {
13 document.getElementById ( " msg_display " ).innerHTML = arg;
14 }
15 function CallTheServer(arg,context)
16 {
17 <%= ClientScript.GetCallbackEventReference( this , " arg " , " ReceiveServerData " , " context " ) %>
18 }
19 // --></mce:script>
20 </ head >
21 < body >
22 < form id = " form1 " runat = " server " >
23 < div >
24 < input id = " testmsg " type = " text " value = " Hello,World! " style = " width: 214px " >< br />
25 < input type = " button " value = " 單擊這個 " onclick = " CallTheServer(document.getElementById('testmsg').value) " />
26 提交给服务器的CallBack
27
28 < div id = " msg_display " style = " background: yellow; font-weight: bold; font-size: 13px " mce_style = " background: yellow; font-weight: bold; font-size: 13px " >
29 从服务器返回的信息在这里显示... </ div >
30 </ div >
31 </ form >
32 </ body >
33 </ html >
34
35 2 、CallBack.aspx.cs
36 using System;
37 using System.Collections;
38 using System.Configuration;
39 using System.Data;
40 using System.Linq;
41 using System.Web;
42 using System.Web.Security;
43 using System.Web.UI;
44 using System.Web.UI.HtmlControls;
45 using System.Web.UI.WebControls;
46 using System.Web.UI.WebControls.WebParts;
47 using System.Xml.Linq;
48 using System.Text;
49 namespace AJAX
50 {
51 public partial class CallBack : System.Web.UI.Page,ICallbackEventHandler
52 {
53 protected void Page_Load( object sender, EventArgs e)
54 {
55
56 }
57 // Summary:
58 // Returns the results of a callback event that targets a control.
59 //
60 // Returns:
61 // The result of the callback.
62 StringBuilder builder = new StringBuilder();
63 public string GetCallbackResult()
64 {
65 return builder.ToString();
66 }
67 //
68 // Summary:
69 // Processes a callback event that targets a control.
70 //
71 // Parameters:
72 // eventArgument:
73 // A string that represents an event argument to pass to the event handler.
74 public void RaiseCallbackEvent( string eventArgument)
75 {
76 builder.Append( " 服务器callback得到了您输入的信息: " + eventArgument + " <br/>您的IP地址是: " );
77 builder.Append(Request.UserHostAddress);
78 builder.Append( " <br/>当前服务器的时间: " );
79 builder.Append(DateTime.Now.ToLocalTime());
80 }
81 }
82 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值