网络编程

ASP.NET Ajax Library功能简介

发布制作:admin  发布日期:2011/6/8

有很久一段时间我的BLOG上没有出现AJAX相关讯息了,主要当然是因为绝大部分的重心都放到了Silverlight身上(可预期的未来应该也会是如此)。但由于工作上的需要,最近还是回头看了一下即将推出的ASP.NET Ajax Library...,顺便找了一下网络上的讯息,看这个态势我猜想应该不少ASP.NET开发人员忽略掉了这个其实已经beta很久即将随着VS2010推出的javascript Library,当然,也可能是因为您已经在使用jQuery了。

不过仔细看看ASP.NET Ajax Library当中还是有不少精彩的功能,同时现在微软针对AJAX javascript Library也提供了CDN(content delivery network)服务,让您可以直接在页面上引用位于微软的javascript档案,而不再需要把档案放在自己的项目中。

后面如果时间允许,我也会陆续介绍ASP.NET Ajax Library中的一些功能,以及和jQuery的整合方式。首先来看ASP.NET Ajax Library中Client Controls的使用(底下的范例是水印的TextBox):

以下为引用的内容:

lt;head>
<title>Untitled Page</title>
<style type="text/css">
.wm {
color:Gray
}
</style>
<!--從CDN引用js-->
<script src="http://ajax.microsoft.com/ajax/jquery
/jquery-1.3.2.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/beta/0911
/Start.debug.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/beta/0911
/extended/ExtendedControls.debug.js" type="text/javascript"></script>
<script type="text/javascript">
//建立watermark
Sys.require(Sys.components.watermark, function() {
$("#TextBoxName").watermark("<請輸入您的姓名>", "wm");
});
</script>

以下为引用的内容:

lt;/head>
<body>
<input type="text" id="TextBoxName" size="50" /> //實際的TextBox
</body>
<head>
<title>Untitled Page</title>
<style type="text/css">
.wm {
color:Gray
}
</style>
<!--從CDN引用js-->
<script src="http://ajax.microsoft.com/ajax/jquery
/jquery-1.3.2.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/beta/0911
/Start.debug.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/beta/0911/extended
/ExtendedControls.debug.js" type="text/javascript"></script>
<script type="text/javascript">
//建立watermark
Sys.require(Sys.components.watermark, function() {
$("#TextBoxName").watermark("<請輸入您的姓名>", "wm");
});
</script>
</head>
<body>
<input type="text" id="TextBoxName" size="50" /> //實際的TextBox
</body>

请注意上面这段脚本是HTML Code, 没有一丁点的ASP.NET Server Code, 单纯只是透过ASP.NET Ajax Library与javascript来呈现出水印的TextBox(其中还用到了一点点jQuery语法。回头看前面的HTML与javascript Code,这中间有相当多的新技术,包含AJAX Script Loader, ASP.NET Ajax Library中的Client Controls如果您暂时不打算进入Silverlight丰富的世界却又希望能够在HTML页面上呈现出较优质的效果,那即将配合VS2010推出的ASP.NET Ajax Library是一个不错的选择。由于ASP.NET Ajax Library现在已经是开放原始码的跨浏览器平台javascript函式库项目,因此可以想见的,你在ASP, PHP或是其它的Pure Web Application开发技术当中也一样可以使用。