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

推荐订阅源

H
Help Net Security
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cisco Talos Blog
Cisco Talos Blog
P
Privacy & Cybersecurity Law Blog
I
Intezer
Y
Y Combinator Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
Netflix TechBlog - Medium
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Stack Overflow Blog
Stack Overflow Blog
Hacker News: Ask HN
Hacker News: Ask HN
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
T
Tor Project blog
C
Cybersecurity and Infrastructure Security Agency CISA
云风的 BLOG
云风的 BLOG
博客园_首页
V2EX - 技术
V2EX - 技术
T
Threat Research - Cisco Blogs
腾讯CDC
宝玉的分享
宝玉的分享
博客园 - 叶小钗
罗磊的独立博客
S
Securelist
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
Scott Helme
Scott Helme
博客园 - 司徒正美
W
WeLiveSecurity
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Secure Thoughts
NISL@THU
NISL@THU
N
News and Events Feed by Topic
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
K
Kaspersky official blog
IT之家
IT之家

博客园 - Arthur_wuancheng(大步牛)

练手之作:易元威客任务发布系统(2) 练手之作:易元威客任务发布系统(1) 人生一世 草木一秋 如何进行高效的项目管理?(转) 项目管理的一点总结 极限编程法一点思考 WEB Service 下实现大数据量的传输 (转) 项目经验(转) Atlas 学习笔记: ajax 改进 by Atlas 存储过程分页,以及动态sql(Sql server) C# 2.0 New Feature(1) WebService Enhancements 2.0 Learning Note ref type & out type Duwamish架构分析篇 (转) 程序编码应保持良好的规范(C#)(转) 也谈代码规范 (转) 如何用正确的方法来写出质量好的软件的75条体会 [转] How to Write to Database by EnterPriseLibrary2005 Logging Application Block(项目心得) 自己正在做电信的互联星空项目,里面用到的xml
ajax for .net in vs2003 like gmail ^_^
Arthur_wuancheng(大步牛) · 2006-01-12 · via 博客园 - Arthur_wuancheng(大步牛)

现在ajax挺流行的,其实早就有这玩艺了,记得以前的公司张工利用xmlhttp对象做的,
那时侯还很繁琐,写得一大堆.

上个月在北京的一位朋友告诉我 .net早就有第三方封装的ajax
上msdn 查了一下 结果就看到这个
http://www.schwarz-interactive.de/

Ajax.NET Professional

呵呵,这么早就有了,觉得自己都和时代脱节了

赶快下载下来试验一下,

一直倾心于gmail 可以提示你的输入地址,

如果数据库没有的话,还能把新的记入,下次你就可以不会吹灰之力,很方便

看看步骤

1.首先加入AjaxPro.dll,using它

2. web.config  加一句

    <httpHandlers>
        
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
    
</httpHandlers>

3.我们看看.cs文件里需要完成什么

4.要注册一下这个类的类型

  private void Page_Load(object sender, System.EventArgs e)
  
{
   
// 在此处放置用户代码以初始化页面
   Utility.RegisterTypeForAjax(typeof( AjaxDemoOwn1.AjaxGetData));  //我这个类的完整namespace

  }

5.我们需要从数据库取一些数据出来,做一个数据库的查询,传入参数就是我们敲入的一个个字母,他会去数据库做查询,这样就能实现动态提示了,这里我就用了Northwind库里面customers表,我们就提示名字把!^_^
方法前要加 [AjaxMethod]

[AjaxMethod]
  
public string getDataByTextBox( string inputString )
  
{
   
string temp = "";
   
if (inputString != "")
   
{
    
string mySelectQuery = "SELECT ContactName FROM Customers where ContactName like '" +inputString+"%'";
    SqlConnection myConnection 
= new SqlConnection(@"server=ZTE-WUANCHENG\wuancheng_zte;database=Northwind;User ID=sa;password=;Persist Security Info=true;");
    SqlCommand myCommand 
= new SqlCommand(mySelectQuery,myConnection);
    myConnection.Open();
    SqlDataReader myReader 
= myCommand.ExecuteReader();
    
    
try 
    
{
     
while (myReader.Read()) 
     
{
      temp 
= temp + myReader.GetString(0)+"" ;
     }

    }

    
finally 
    
{
     
// always call Close when done reading.
     myReader.Close();
     
// always call Close when done reading.
     myConnection.Close();
    }

   }
  
   
return temp;
  }

这个代码是很常规的,相信大家都能看懂

6. 下面完成我们的页面aspx部分
加入2个框

一个text 输入用的

    <INPUT type="text" id="Text1" onkeyup="javascript:doTest2();void(0);"
            style
="Z-INDEX: 102; LEFT: 104px; WIDTH: 200px; POSITION: absolute; TOP: 80px; HEIGHT: 22px"
            size
="28">

一个text area  提示用的

        <TEXTAREA style="Z-INDEX: 103; LEFT: 104px; WIDTH: 200px; POSITION: absolute; TOP: 104px; HEIGHT: 288px"
            rows
="18" cols="22" id="Text2">
        
</TEXTAREA>

大家看到了 Text1 有一个 onkeyup 她去调用了 doTest2()这个javascript

        <script type="text/javascript" defer>
        
        
function doTest2()
        
{
            
            AjaxDemoOwn1.AjaxGetData.getDataByTextBox(document.getElementById(
"Text1").value, doTest2_callback);
        }

        
function doTest2_callback(res)
        
{
            
var p = res.value;
            document.getElementById(
"Text2").value = p;
        }

        
</script>

这里就去作异步调用AjaxDemoOwn1.AjaxGetData.getDataByTextBox(string)方法了,
我们就把text1的值传入,得到返回值放入textarea 中,OK !大功告成

页面无刷新,跟着你的按键变化,好爽,^_^

还是很简单的,有兴趣可以看看,下面想作save数据库操作,这样就有记忆能力了!

posted on 2006-01-12 11:45  Arthur_wuancheng(大步牛)  阅读(2033)  评论()    收藏  举报