这两天培训的.Net framework让我对微软的东西有了进一步的了解。以前只是认为MS的东西就是拖来拖去的,并没有其他让人更惊喜的功能。今天介绍了ASP AJAX ToolKit以后,真是让人大跌眼镜。
举些简单的例子,比如说要加一个这样的效果,一个Textbox输入2个数字以后,要有联想功能的把所有数据库或者web service上以这两个数字打头的列出来。在ASP.NET里只用一句话就可以了。
<ajaxToolkit:AutoCompleteExtender
ID="AutoCompleteExtender1"
TargetControlID="ZipCode"
ServicePath="ZipCodeService.asmx"
ServiceMethod="GetMatchingZipCodes"
MinimumPrefixLength="2"
CompletionListElementID="ctl00_MainPlaceHolder_ZipCodeComp
letionList"
CompletionSetCount="15" runat="server" />
ID="AutoCompleteExtender1"
TargetControlID="ZipCode"
ServicePath="ZipCodeService.asmx"
ServiceMethod="GetMatchingZipCodes"
MinimumPrefixLength="2"
CompletionListElementID="ctl00_MainPlaceHolder_ZipCodeComp
letionList"
CompletionSetCount="15" runat="server" />
太简单了,这要是在j2ee中作起来就麻烦多了,不过有了DWR等建立在J2EE上的AJAX框架,做起来也容易多了。
再比如,一个ZipCode要有提示输入5个数字的。首先要过滤,只保留数字和-。又是一句话,电话号码也要这样:
<ajaxToolkit:FilteredTextBoxExtender
ID="FilterTextBoxExtender1"
TargetControlID="ZipCode" FilterType="Custom"
ValidChars="0123456789-"
runat="server" />
<ajaxToolkit:FilteredTextBoxExtender
ID="FilterTextBoxExtender2"
TargetControlID="Phone" FilterType="Custom"
ValidChars="0123456789()-. "
runat="server" />
ID="FilterTextBoxExtender1"
TargetControlID="ZipCode" FilterType="Custom"
ValidChars="0123456789-"
runat="server" />
<ajaxToolkit:FilteredTextBoxExtender
ID="FilterTextBoxExtender2"
TargetControlID="Phone" FilterType="Custom"
ValidChars="0123456789()-. "
runat="server" />
然后提示输入5个数字
<ajaxToolkit:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender1"
TargetControlID="ZipCode" WatermarkText="xxxxx"
runat="server" />
<ajaxToolkit:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender2"
TargetControlID="Phone" WatermarkText="xxx-xxx-xxxx"
runat="server" />
ID="TextBoxWatermarkExtender1"
TargetControlID="ZipCode" WatermarkText="xxxxx"
runat="server" />
<ajaxToolkit:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender2"
TargetControlID="Phone" WatermarkText="xxx-xxx-xxxx"
runat="server" />
显示出来的效果就是这样的