惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - Let's DotNet

Generating SSH Keys for Git Keyboard shortcuts for Windows C# 类初始化顺序 - Let's DotNet Office 2007安装后Google拼音输入法莫名其妙消失了,换成了微软拼音 在装有SAP客户端后安装VS2003时出错 无法通过Project Professional 2003连接到Project Server 2003的解决办法(转) AutoCoder——全新自动代码框架 基于性能的编程技巧点滴 "Union" in Oracle - Let's DotNet Atlas Project (转) DB2编程技巧 动态添加控件的一个注意点 SQL Server 高阶应用 限制多行文本框(TextArea)中输入文字的长度(转) 给自己的某个文件夹的文件做一个列表(转) Google 桌面搜索... Eclipse 3.0资料收集(转) 一种改进的轻量级.NET应用程序性能测试框架 ASP.NET 应用程序性能优化
Difference between ICallbackEventHandler and AJAX
Let's DotNet · 2006-09-02 · via 博客园 - Let's DotNet

  作为ASP.NET 2.0 的新特性,ICallbackEventHandler给我们完整的AJAX体验,而且实现/控制更加简单;但事实上ICallbackEventHandler并不是一个完整的AJAX实现,否则也不会有Atlas的开发~

  目前来看,ICallbackEventHandler是一种轻量级的类AJAX实现,优点是不用周折于客户端创建XMLHttpRequest对象时的兼容性问题,而把重点放在局部HttpRequest的处理上;缺点(至少目前是)是向服务端提交数据不太方便,不能是Post方式,只能是一个字符串~

  下面是随意写的一个hello word,

   Page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>Hello ICallBackHandler</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
&nbsp;<br />
        
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
        
&nbsp;<br />
        
<br />
        
<br />
        
        
<div style="color:Red" id="ddd"></div>
        
</div>
    
</form>
</body>
</html>

  Code-behind

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page,ICallbackEventHandler
{
    
private const string CALLBACK_PARAM = "callbackTest";
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!Page.IsPostBack)
        
{
            
        }

        
        InitClientResource();
    }


    
private void InitClientResource()
    
{
        
string callBackStartScript = string.Empty;
        
string callBackEndScript = string.Empty;

        callBackStartScript 
= "function callServer(arg,context) {  " + Page.ClientScript.GetCallbackEventReference(this"arg""callEnd""context"+ "; }  \r\nfunction getContext() { return document.getElementById('" + this.TextBox1.ClientID + "').value; } \r\n";
        
        Page.ClientScript.RegisterClientScriptBlock(
this.GetType(), "callServer", callBackStartScript, true);

        callBackEndScript 
= "function callEnd(arg,context) { document.getElementById('ddd').innerText = arg;}";
        Page.ClientScript.RegisterClientScriptBlock(
this.GetType(), "callEnd", callBackEndScript, true);

        Button1.OnClientClick 
= string.Format("callServer({0},'{1}'); return false;","getContext()" ,CALLBACK_PARAM);
    }


    
ICallbackEventHandler Members
}

  Reference:
[1] http://msdn2.microsoft.com/en-us/library/ms178208.aspx;
[2] http://dotnet.sys-con.com/read/121828_p.htm
[3] http://staff.develop.com/ballen/blog/PermaLink.aspx?guid=c35c43f6-5686-40ee-9752-8095a848d821