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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
SecWiki News
SecWiki News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Forbes - Security
Forbes - Security
Schneier on Security
Schneier on Security
W
WeLiveSecurity
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
O
OpenAI News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
S
SegmentFault 最新的问题
Help Net Security
Help Net Security
G
GRAHAM CLULEY
Latest news
Latest news
V
Visual Studio Blog
The Cloudflare Blog
T
Troy Hunt's Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
I
InfoQ
Know Your Adversary
Know Your Adversary
B
Blog RSS Feed
V2EX - 技术
V2EX - 技术
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Heimdal Security Blog
Y
Y Combinator Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
P
Palo Alto Networks Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tor Project blog
T
Threat Research - Cisco Blogs
博客园 - 三生石上(FineUI控件)
Cloudbric
Cloudbric
博客园 - Franky
博客园 - 叶小钗
S
Security @ Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
T
Threatpost
MongoDB | Blog
MongoDB | Blog
V
Vulnerabilities – Threatpost
Martin Fowler
Martin Fowler

博客园 - 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)  评论()    收藏  举报