仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 406|回复: 8
打印 上一主题 下一主题

[学习教程] ASP教程之Common ASP.NET Code Techniques (DPC&...

[复制链接]
不帅 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:26:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
ASP在国内异常流行,因为国内大多使用的是盗版的Windows和盗版的SQLServer,而ASP+COM+SQLServer实际上也是一种不错的搭配,其性能也不输于PHP+MYSQL,特别是Windows系统和SQLServer都有图形界面,比APACHE和MYSQL易于维护,因此对于不重视知识产权的国家来说也是一种不错的选择。OneofthethingsthatIpersonallyfoundfrustratingwithclassicASPwasthedifficultyassociatedwithcompletingmanycommonWeb-relatedtasks.Forexample,theneedtoallowWebvisitorstouploadfilestotheWebserverisfairlycommonforWebdevelopers;however,withclassicASPtheonlywaytoaccomplishthiswithoutmuchdifficultywasthroughtheuseofathird-partyCOMcomponent.Similarly,commontaskssuchassendingemails,readingandwritingtotheWindowsEventLog,workingwiththeWebserversfilesystem,anddynamicallygeneratingimagesbasedondatabaseinformationwerealltricky,ifnotimpossible,withouttheaidofaCOMcomponent.

ThankfullythishasallchangedwithASP.NET.NowWebdeveloperscaneasilyaccomplishaplethoraofcommontaskswithouttheneedtocreateorbuyathird-partycomponentthanksinlargeparttoASP.NETbeingpartoftherobust.NETFramework.WhenyouinstalltheASP.NETsoftwareonyourcomputerfromtheCDaccompanyingthisbook,inadditiontotheASP.NETengine,theentire.NETFrameworkwillbeinstalled.The.NETFrameworkconsistsofhundredsofclassesbrokendownintoanumberoflogicalnamespaces.TheseclassesprovidethemethodsandpropertiesneededtocreatepowerfulWindowsapplications,fromstandalonedesktopappstoInternetapplications.

ASP.NETWebpagescanutilizeanyofthesehundredsofclasses,givingASP.NETWebpagesthepowerandflexibilitythatclassicASPdeveloperscouldonlyreceivewiththeuseofbulkyCOMcomponents.InthischapterwewillexaminemanyofthenewfeaturesthatweredifficulttoimplementwithclassicASPbutcanbeeasilyperformedwithanASP.NETWebpage.

1.UsingCollections
Mostmodernprogramminglanguagesprovidesupportforsometypeofobjectthatcanholdavariablenumberofelements.Theseobjectsarereferredtoascollections,andtheycanhaveelementsaddedandremovedwitheasewithouthavingtoworryaboutpropermemoryallocation.IfyouveprogrammedwithclassicASPbefore,youreprobablyfamiliarwiththeScripting.Dictionaryobject,acollectionobjectthatreferenceseachelementwithatextualkey.Acollectionthatstoresobjectsinthisfashionisknownasahashtable.

Therearemanytypesofcollectionsinadditiontothehashtable.Eachtypeofcollectionissimilarinpurpose:Itservesasameanstostoreavaryingnumberofelements,providinganeasyway,ataminimum,toaddandremoveelements.Eachdifferenttypeofcollectionisuniqueinitsmethodofstoring,retrieving,andreferencingitsvariouselements.

The.NETFrameworkprovidesanumberofcollectiontypesforthedevelopertouse.Infact,anentirenamespace,System.Collections,isdedicatedtocollectiontypesandhelperclasses.EachofthesecollectiontypescanstoreelementsoftypeObject.Becausein.NETallprimitivedatatypes―string,integers,date/times,arrays,andsoon―arederivedfromtheObjectclass,thesecollectionscanliterallystoreanything!Forexample,youcoulduseasinglecollectiontostoreacoupleofintegers,aninstanceofaclassicCOMcomponent,astring,adate/time,andtwoinstancesofacustom-written.NETcomponent.Mostoftheexamplesinthissectionusecollectionstohouseprimitivedatatypes(strings,integers,doubles).However,Listing2.1.8(whichappearsinthe"SimilaritiesAmongtheCollectionTypes"section)illustratesacollectionofcollections―thatis,acollectiontypethatstoresentirecollectionsaseachofitselements!

Throughoutthissectionwellexaminefivecollectionsthe.NETFrameworkoffersdevelopers:theArrayList,theHashtable,theSortedList,theQueue,andtheStack.Asyoustudyeachofthesecollections,realizethattheyallhavemanysimilarities.Forexample,eachtypeofcollectioncanbeiteratedthroughelement-by-elementusingaForEach...NextloopinVB(oraforeachloopinC#).Eachcollectiontypehasanumberofsimilarlynamedfunctionsthatperformthesametasks.Forexample,eachcollectiontypehasaClearmethodthatremovesallelementsfromthecollection,andaCountpropertythatreturnsthenumberofelementsinthecollection.Infact,thelastsubsection"SimilaritiesAmongtheCollectionTypes"examinesthecommontraitsfoundamongthecollectiontypes.

WorkingwiththeArrayListClass
ThefirsttypeofcollectionwelllookatistheArrayList.WithanArrayList,eachitemisstoredinsequentialorderandisindexednumerically.Inourfollowingexamples,keepinmindthatthedeveloperneednotworryhimselfwithmemoryallocation.Withthestandardarray,thedevelopercannoteasilyaddandremoveelementswithoutconcerninghimselfwiththesizeandmakeupofthearray.Withallthecollectionswellexamineinthischapter,thisisnolongeraconcern.

Adding,Removing,andIndexingElementsinanArrayList
TheArrayListclasscontainsanumberofmethodsforaddingandremovingObjectsfromthecollection.TheseincludeAdd,AddRange,Insert,Remove,RemoveAt,RemoveRange,andClear,allofwhichwellexamineinListing2.1.1.TheoutputisshowninFigure2.1.

Listing2.1.1ForSequentiallyAccessedCollections,UsetheArrayList
1:<scriptlanguage="vb"runat="server">
2:
3:SubPage_Load(senderasObject,easEventArgs)
4:CreatetwoArrayLists,aTerritoriesandaStates
5:DimaTerritoriesasNewArrayList
6:DimaStatesasNewArrayList
7:
8:UsetheAddmethodtoaddthe50statesoftheUS
9:aStates.Add("Alabama")
10:aStates.Add("Alaska")
11:aStates.Add("Arkansas")
12:...
13:aStates.Add("Wyoming")
14:
15:Buildupourlistofterritories,whichincludes
16:all50statesplussomeadditionalcountries
17:aTerritories.AddRange(aStates)addall50states
18:aTerritories.Add("Guam")
19:aTerritories.Add("PuertoRico")
20:
21:WedlikethefirstterritorytobetheDistrictofColumbia,
22:sowellexplicitlyaddittothebeginningoftheArrayList
23:aTerritories.Insert(0,"DistrictofColumbia")
24:
25:Displayalloftheterritorieswithaforloop
26:lblTerritories.Text="<i>Thereare"&aTerritories.Count&_
27:"territories...</i><br>"
28:
29:DimiasInteger
30:Fori=0toaTerritories.Count-1
31:lblTerritories.Text=lblTerritories.Text&_
32:aTerritories(i)&"<br>"
33:Next
34:
35:Wecanremoveobjectsinoneoffourways:
36:...Wecanremoveaspecificitem
37:aTerritories.Remove("Wyoming")
38:
39:...Wecanremoveanelementataspecificposition
40:aTerritories.RemoveAt(0)willgetridofDistrict
41:ofColumbia,
42:thefirstelement
43:
44:Displayalloftheterritorieswithforeachloop
45:lblFewerTerritories.Text="<i>Therearenow"&_
46:aTerritories.Count&"territories...</i><br>"
47:
48:DimsasString
49:ForEachsinaTerritories
50:lblFewerTerritories.Text=lblFewerTerritories.Text&_
51:s&"<br>"
52:Next
53:
54:...wecanremoveachunkofelementsfromthe
55:arraywithRemoveRange
56:aTerritories.RemoveRange(0,2)willgetridofthe
57:firsttwoelements
58:
59:Displayalloftheterritorieswithforeachloop
60:lblEvenFewerTerritories.Text="<i>Therearenow"&_
61:aTerritories.Count&"territories...</i><br>"
62:
63:ForEachsinaTerritories
64:lblEvenFewerTerritories.Text=lblEvenFewerTerritories.Text&_
65:s&"<br>"
66:Next
67:
68:Finally,wecancleartheENTIREarrayusingtheclearmethod
69:aTerritories.Clear()
70:EndSub
71:
72:</script>
73:
74:<html>
75:<body>
76:<b>TheTerritoriesoftheUnitedStates:</b><br>
77:<asp:labelid="lblTerritories"runat="server"/>
78:
79:<p>
80:
81:<b>AftersomeworkingwiththeTerritoriesArrayList:</b><br>
82:<asp:labelid="lblFewerTerritories"runat="server"/>
83:
84:<p>
85:
86:<b>AfterfurtherworkingwiththeTerritoriesArrayList:</b><br>
87:<asp:labelid="lblEvenFewerTerritories"runat="server"/>
88:</body>
89:</htm
强大的可扩展性。ASP具有强大的扩展性,可以实现与多种网络、硬件设备的连接:通过专用的通讯线路远程接入企业;通过远程拨号服务器为远程拨号客户提供服务;通过WAP为移动电话互联网客户服务。
飘飘悠悠 该用户已被删除
沙发
发表于 2015-1-19 12:28:57 | 只看该作者
ASP(ActiveServerPages)是Microsfot公司1996年11月推出的WEB应用程序开发技术,它既不是一种程序语言,也不是一种开发工具,而是一种技术框架,不须使用微软的产品就能编写它的代码,能产生和执行动态、交互式、高效率的站占服务器的应用程序。
愤怒的大鸟 该用户已被删除
板凳
发表于 2015-1-25 10:37:51 | 只看该作者
先学习用frontpage熟悉html编辑然后学习asp和vbscript建议买书进行系统学习
只想知道 该用户已被删除
地板
发表于 2015-2-2 21:43:08 | 只看该作者
尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。
小妖女 该用户已被删除
5#
发表于 2015-2-8 07:21:53 | 只看该作者
最近在学asp,不要问我为什么不直接学.net,因为公司网站是asp做的所以有这个需要,卖了本书asp入门到精通,对里面的六大内置对象老是记不住,还有很多属性和方法看的头晕。
分手快乐 该用户已被删除
6#
发表于 2015-2-24 23:39:38 | 只看该作者
没有坚实的理论做基础,那么我们连踏入社会第一步的资本都没有,特别对于计算机专业的学生学好专业知识是置关重要的。在这里我侧重讲一下如何学习ASP,从平时的学习过程中。
变相怪杰 该用户已被删除
7#
发表于 2015-3-7 14:11:08 | 只看该作者
接下来就不能纸上谈兵了,最好的方法其实是实践。实践,只能算是让你掌握语言特性用的。而提倡做实际的Project也不是太好,因为你还没有熟练的能力去综合各种技术,这样只能使你自己越来越迷糊。
兰色精灵 该用户已被删除
8#
发表于 2015-3-15 07:35:59 | 只看该作者
还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。
飘灵儿 该用户已被删除
9#
发表于 2015-3-21 22:01:22 | 只看该作者
尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-10-1 23:48

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表