ASP.NET 2.0 中的无刷新页面

 这几天在微软网站看了一编客户端回客户端回调实现 (C#) 示例 
(网址为:http://msdn2.microsoft.com/zh-CN/library/ms178210.aspx
用它就能实现基本Ajax的原System.Web.UI.ICallbackEventHandler理功能,而不学习一些Ajax框架的东西,感觉挺爽呀,可是运行起报错,后经过仔细查找原来是System.Web.UI.ICallbackEventHandler的接口不是它那样写的,可能它是原来的接口吧。后我照2.0的接口改成下面的样子,运行吗ok,是一个不错无刷新技术。
它的基本原理,微软的试例已经介绍非常祥细了,在此我就不搬门弄斧了,有兴趣的朋友去,去http://www.cnblogs.com/RicCC/archive/2006/09/10/500268.html这个网址看看吧

None.gif <% @ Page Language = " C# "  AutoEventWireup = " true "   CodeFile = " Default.aspx.cs "  Inherits = " _Default "   %>
None.gif
None.gif
<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
None.gif
None.gif
< html xmlns = " http://www.w3.org/1999/xhtml " >
None.gif
< head runat = " server " >
None.gif
< title > 无标题页 </ title >
None.gif  
< script type = " text/javascript " >
None.gif    function LookUpStock()
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        var lb 
= document.forms[0].ListBox1;
InBlock.gif        var product 
= lb.options[lb.selectedIndex].text 
InBlock.gif        CallServer(product, 
"");
ExpandedBlockEnd.gif    }

None.gif    
None.gif    function ReceiveServerData(rValue)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        Results.innerText 
= rValue;
ExpandedBlockEnd.gif    }

None.gif  
</ script >
None.gif
</ head >
None.gif
< body >
None.gif  
< form id = " form1 "  runat = " server " >
None.gif    
< div >
None.gif      
< asp:ListBox ID = " ListBox1 "  Runat = " server " ></ asp:ListBox >
None.gif      
< br  />
None.gif      
< br  />
None.gif      
< button onclick = " LookUpStock() " > Look Up Stock </ button >
None.gif      
< br  />
None.gif      
< br  />
None.gif      Items 
in  stock:  < span ID = " Results " ></ span >
None.gif      
< br  />
None.gif    
</ div >
None.gif  
</ form >
None.gif
</ body >
None.gif
</ html >
None.gif
None.gif
None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Configuration;
None.gif
using  System.Collections;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
None.gif
None.gif
public  partial  class  _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
protected System.Collections.Specialized.ListDictionary catalog;
InBlock.gif
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        String cbReference 
=
InBlock.gif            Page.ClientScript.GetCallbackEventReference(
this,
InBlock.gif            
"arg""ReceiveServerData""context");
InBlock.gif        String callbackScript;
InBlock.gif        callbackScript 
= "function CallServer(arg, context)" +
InBlock.gif            
"" + cbReference + "} ;";
InBlock.gif        Page.ClientScript.RegisterClientScriptBlock(
this.GetType(),
InBlock.gif            
"CallServer", callbackScript, true);
InBlock.gif
InBlock.gif        catalog 
= new System.Collections.Specialized.ListDictionary();
InBlock.gif        catalog.Add(
"monitor"12);
InBlock.gif        catalog.Add(
"laptop"10);
InBlock.gif        catalog.Add(
"keyboard"23);
InBlock.gif        catalog.Add(
"mouse"17);
InBlock.gif
InBlock.gif        ListBox1.DataSource 
= catalog;
InBlock.gif        ListBox1.DataTextField 
= "key";
InBlock.gif        ListBox1.DataBind();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    String returnValue;
InBlock.gif    
public void RaiseCallbackEvent(String eventArgument)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
InBlock.gif        
if (catalog[eventArgument] == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            returnValue 
= "-1";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            returnValue 
= catalog[eventArgument].ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
//
ExpandedSubBlockEnd.gif
    }

InBlock.gif
InBlock.gif    
public string GetCallbackResult()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
return returnValue;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/liuke209/archive/2006/09/10/500094.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值