|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
asp对于服务器的要求较高,一般的服务器如果访问量一大就垮了,不得不重启。创立|静态|数据|数据库CreatingDynamicListBoxesWithCross-BrowserCompatibility
Theaimofthisarticleistolookattheopportunitiesforcreatinglistboxeswherethecontentchangesdynamicallydependingonsomeactiontakenbytheuserinthepage.Whereyouhaveaformthatthevisitorusestoprovideinformation,thistechniqueisoftenuseful.Theprincipleisthateachlistshouldchangeitscontenttomatchsomeconditionspecifiedinanotherlistorcontrolonthepage.
Theexamplewereusingisthatofselectinganaddressfromadatabase,wheretheaddressisspecifiedinseparatefieldsforthestate,city,andstreetaddresspart.Astheuserselectsastatefromalist,thelistofcitieschangestoreflectthoseinthechosenstate.Thesamehappenswhentheuserthenselectsacityfromthatlist,wherethelistofstreetaddressesthenshowsonlytheonesinthatcity.
Welllookatsomeofthewaysthatthismightbeachievedandthenimplementthesolutionthatseemstoofferthebestopportunityforgeneralbrowsercompatibility.WellbeusingthesamplepubsdatabasethatcomeswithallversionsofSQLServer,butyoucaneasilyadaptthecodetouseyourowndata.
TheOptionsAvailable
Thecoreoftheproblemishowwearegoingtogetalistofmatchingcitiesandstreetaddressesfortheselectedstateorcity.Thereareseveraloptionsforfetchingandstoringalltheavailabledataontheclient,andusingthiscacheddata.Alternatively,wecanimplementasolutionthatfetchestherequireddataeachtimeaselectionismade.Thisrequiresmoreconnectionstotheserver,butwillprobablytransferlessdataoverallunlesstheusermakesmanydifferentselections.
InInternetExplorer4or5,wemightconsider:
RemoteDataServices(RDS)?fetcharecordsetfromadatabaseusingtheRDSDataControlobject,whichiscachedontheclient.Thenaccessitthroughtherecordsetpropertyofthedatacontrolandusetheinformationtopopulatethelistboxesondemandbyiteratingthroughorfilteringtherecordset.
TabularDataControl(TDC)?fetchatextfilecontainingthedetailsfromtheserverusingtheRDSTabularDataControlobject.Thenaccessitthroughtherecordsetpropertyofthedatacontrolandusetheinformationtopopulatethelistboxesondemandbyiteratingthroughorfilteringtherecordset.
XMLDataIsland?fetchanXMLdocumentcontainingtheinformationandcacheitontheclient.Thenusetherecordsetpropertyofthedataislandtoaccessthedetailsandpopulatethelistboxesondemand,inthesamewayaswithRDS.
Createahidden<IFRAME>elementandloadtheinformationintoitfromtheserver,thencopyittothelistboxesondemand.
InIE5,usetheHttpRequestobjecttofetchanXMLdocumentfromtheserverandaccessitusingtheXMLDocumentObjectModel(DOM)toextractthedataandpopulatethelistboxes.
InIE5,createaHypertextApplication(HTA)andusetheFileSystemObjecttostoredataontheclientsdisk,thenuseittopopulatethelistboxesondemand.
UsesomekindofcustomappletorActiveXcontroltofetchthedataondemandfromtheserverusingscriptcodeinthepage,andthenusethedatatopopulatethelistboxes.
Meanwhile,inNavigator4.xor6wecould:
Useahidden<LAYER>elementandloadtheinformationintoitfromtheserver,thencopyittothelistboxesondemand.
Usesomekindofcustomapplettofetchthedataondemandfromtheserverusingscriptcodeinthepage,andthenusethedatatopopulatethelistboxes.
However,foraCompatibleSolution:
WiththeexceptionofacustomJavaapplet,noneofthesemethodsiscompatibleacrossarangeofdifferentbrowsers.Onetechniquethatshouldwork,however,istheuseofframesets.Wecouldputeachlistboxonaseparatepageinaseparateframe,andreloadthatpageondemand;usingASPtofillthelistwiththematchingvalues.
Analternativeapproachwouldbetouseaframesetinwhichoneframeisnotvisible.Wecanthenloadthisframewithapagecontainingthedatawerequireeachtimeweneedtoupdatethecontentsofanyofthelistboxes.Thenallwehavetodoiscopythedataintotheappropriatelistbox.Welllookatthissecondsolutionfirst,asitseemstoofferthebestcombinationofusabilityandcompatibility.
CreatingaHiddenFrame
Thefirstissueishowwearegoingtocreateahiddenframewithinaframeset.Ifwesettheframewidthtozero,Navigatorwillfailtoloadthecontents.ThisisprobablyasensibleactiononNavigatorsbehalf,becausethecontentwontbevisibleanyway.However,thatdoesnthelpus.Instead,wecreateaframesetcontainingoneframethatisonepixelwide,andanothertofilltheremainderofthebrowserwindow.Byremovingtheframebor</p>使用filesystemobject,可以对服务器上的文件进行操作,浏览、复制、移动、删除等。有ado的支持,asp对数据库的操作非常得心应手。你甚至可以像使用本地数据库那样,管理远程主机上的数据库,对表格、记录进行各种操作。 |
|