Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .Net - P8

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:50

0
50
lượt xem
7
download

Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .Net - P8

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Tham khảo tài liệu 'programming microsoft sql server 2000 with microsoft visual basic .net - p8', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả

Chủ đề:
Lưu

Nội dung Text: Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .Net - P8

  1. A t y pical ASP. NET applicat ion will be r un in an env ir onm ent in which m any browsers ar e connect ed t o a single Web serv er or a farm of Web serv er s. For sim plicit y , I discuss t he case of t he single Web ser ver, but t he sam e general principles apply t o a far m of Web ser vers. The asynchr onous nat ure of com m unicat ion bet ween a Web serv er and brow sers facilit at es t he m aint enance of a large num ber of concurr ent br owser sessions w it h a single Web serv er. Each of t hese br owsers can have a differ ent session st at e wit h t he Web serv er. I n ot her words, t he sam e page can show differ ent cont ent s t o differ ent users depending on t he int eract ions of each user w it h t he Web serv er . At t he sam e t im e, a dat abase ser ver can pr ov ide a consist ent set of inform at ion acr oss m ult iple browser sessions. Anot her defining char act er ist ic of Web applicat ions is t hat a Web serv er can serv e pages t o m any differ ent k inds of browsers. Alt hough all browser t ypes r ender HTML code in pages ser ved fr om a Web ser ver, t he r endering isn’t necessarily invariant fr om one brow ser t ype t o t he next . Som e br owsers handle client - side script ing in one language but not anot her . Different browser versions t arget different HTML v ersions ( 3.2 and 4.0 are t wo com m on HTML v ersions) . Som e support absolut e posit ioning, but support isn’t univ ersal for t his feat ure. For differences such as t hose not ed, it ’s not uncom m on for Web applicat ions t o hav e t o “sniff” t he br owser t y pe t o det erm ine it s char act erist ics and t hen send a page t hat is r endered and behav es well on t hat br ow ser. ASP.NET offers a couple of approaches t o handling Web applicat ion dev elopm ent issues. First , ASP.NET can elicit HTML from Web serv ers in an at t em pt t o m inim ize t he im pact of different browser t ypes on t he way t hat a page appears in a browser . Second, ASP.NET has built - in capabilit ies for det ect ing br owser t y pes Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  2. and t heir capabilit ies. Your applicat ions can t ap t hese capabilit ies t o dir ect browsers t o pages t hat are r endered well wit hin t hem . N ot e I t ’s a big drain on lim it ed Web applicat ion developm ent resources t o det ect browsers and prepare m ult iple pages t hat are rendered w ell in different brow sers. As a business em ploy ing t alent ed Web developers, wouldn’t you r at her t hose developers spend t heir t im e cr eat ing m or e useful cont ent in different pages t han creat ing m ult iple copies of a sm aller num ber of less useful pages so as t o opt im ize for differ ent browser s? Because ASP.NET is fr ee wit h t he I I S 5.0 Web server, and t he I nt ernet Ex plorer br owser is free wit h m ost Microsoft pr oduct s and from Microsoft ’s I nt ernet sit e, I recom m end you use t he I nt ernet Explor er browser for your ASP.NET applicat ions. Not e t hat Micr osoft didn’t encourage m e t o m ak e t his st at em ent . I nst ead, I m ak e t he st at em ent on t he basis of m y obser vat ions about how t ax ing it is on organizat ions t o creat e Web solut ions t hat work well wit h m ult iple br owsers. Pa ge s a n d t h e Pa ge Cla ss As indicat ed in Chapt er 8, ASP.NET builds on ASP. For exam ple, Web ser vers can discer n an ASP.NET page based on it s ext ension, .aspx. The ex t ension for an ASP.NET page is t he sam e as t he ext ension of ASP pages w it h an x appended t o it . For exam ple, an ASP.NET page w ill have a nam e lik e m ypage.aspx. Any ASP.NET solut ion can hav e m ult iple pages wit hin it . You can designat e one page as t he st art page for an applicat ion. ( Ther e is no st art up obj ect as t her e is wit h Windows applicat ions.) An ASP.NET solut ion can cont ain m ult iple pages, and users can nav igat e wit hin and bet ween t he pages of a solut ion. I n addit ion, y ou can navigat e t o old .asp page files or ev en ot her t ypes of files, such as .ht m or .ht m l files. When an ASP.NET applicat ion opens an .aspx file, t he applicat ion launches t he Page_Load ev ent procedure ( unless you rem ov e it ) . The Page class is a program m ing abst ract ion of an .aspx file. This Page class prov ides m any valuable serv ices. For exam ple, you can use a page’s I sPost Back pr opert y t o det erm ine whet her a page is being displayed for t he first t im e in a session or is t he result of a browser post ing a page back t o a Web serv er . A page’s Session propert y enables your applicat ion t o m anage var iables across m ult iple asy nchronous connect ions t o a Web serv er fr om a br owser w it hin a session. A page’s Applicat ion propert y point s t o an Applicat ion obj ect for shar ing var iable values across an applicat ion’s users. One of t he m ost excit ing feat ur es of t he Page class is t he way t hat it aut om at es t he m anagem ent of form at t ing and cont ent bet ween round- t r ips; I ’ll discuss t his t opic m or e fully in t he “Session St at e Managem ent ” sect ion. Wit h t he Response and Request pr oper t ies for a page, you can ex plicit ly m anage t he exchange of inform at ion bet ween a Web ser ver and a brow ser. The Response pr opert y enables you t o echo cont ent t o Web pages so t hat you can m onit or t he ingoing and out going v alues for cont rols and variable v alues on Web pages. Developers w ill r ecognize t his capabilit y as part icular ly handy for debugging. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  3. My personal favor it e feat ure of ASP.NET is t he way t hat it separat es page lay out issues from pr ogram logic. Those of y ou fam iliar wit h ASP w ill r ecall how you had t he opport unit y ( indeed it was a r equir em ent ) t o m ix HTML layout w it h your script for m anaging t he logic on a page. Alt hough you can st ill do t his, Visual St udio support s a t w o- file st ruct ur e for t he Web page class. The file w it h t he .aspx ext ension cont ains t he HTML lay out code. A new, second, file cont ains t he program logic. This file’s ext ension depends on t he pr ogram m ing language. For exam ple, if y our Web page file has t he nam e y ourpage.aspx, it s code file in Visual Basic w ill hav e t he nam e y ourpage.aspx.vb. The page w it h t he .aspx ext ension cont ains cont r ols, such as labels, t ext box es, and list box es. The code file ( w it h t he aspx.vb ext ension) includes page init ializat ion code, event procedur es for t he obj ect s on t he page, and ot her r out ines and declarat ions t o m anage t he behavior of a page. An ASP.NET applicat ion t hat y ou develop w it h Visual St udio has t w o folders for m anaging a solut ion. Your .aspx and .aspx.vb files r eside in a folder on t he Web serv er. The pr oj ect folder ’s default locat ion is in t he www root subdir ect ory of t he I net pub folder of t he I I S serv er host ing y our applicat ion. You can hav e m ult iple files wit hin t he Web folder for a solut ion, including ot her Web pages and graphic files. You open a Web solut ion by inv ok ing any .aspx file wit hin t he folder on t he Web serv er . A second folder in your Visual St udio solut ion dir ect or y cont ains t he solut ion file ( .sln) for an ASP.NET pr oj ect . This second folder is t he sam e one Visual St udio uses t o st ore t he files for y our Windows applicat ion solut ions. Use t he .sln file t o open y our solut ion in Visual St udio when you want t o edit t he design of a solut ion. Bot h t he Web folder and t he regular Windows folder can hav e t he sam e nam e t o facilit at e t heir coordinat ion. Con t r ols on Pa ge s You st art an ASP.NET proj ect in Visual St udio .NET by click ing New Pr oj ect on t he Visual St udio .NET St art Page and t hen highlight ing t he ASP.NET Web Applicat ion t em plat e. Designat e a folder nam e for your new pr oj ect . The default locat ion is on t he localhost I I S ser ver. See t he ov er v iew of ASP.NET in Chapt er 8 for t he t hree elem ent s t hat y ou need t o cr eat e ASP.NET solut ions. As Visual St udio .NET st art s t he proj ect , it creat es a Web sit e for t he solut ion on t he Web serv er. When t he proj ect opens, y ou w ill v iew an em pt y Web page ( w it h t he .aspx ext ension) . The default nam e for t he page is WebForm 1.aspx. You can assign a new nam e t hat is m or e m eaningful in t erm s of your applicat ion by r ight - clicking t he file’s nam e in Solut ion Explorer and choosing Renam e t o assign a new nam e. Use t he Toolbox t o add cont r ols t o a blank page. You can display t he Toolbox by choosing Toolbox from t he View m enu from w it hin Design v iew for t he st art up page. There ar e t hr ee cat egories of nat ive cont rols t hat you ar e lik ely t o add t o an .aspx page. These r eside in t hree separat e t abs wit hin t he Toolbox. • First , you can click t he HTML t ab in t he Toolbox t o expose classic HTML cont r ols. These cont rols can operat e as HTML elem ent s or as a new t ype of HTML serv er cont rol. I f you are used t o building Web solut ions w it h ASP or som e ot her Web developm ent language ( such as Perl) , you pr obably alr eady have a w ork ing know ledge of HTML cont rols. One k ey dist inct ion bet ween classic HTML form cont rols and HTML server cont r ols is t hat serv er cont rols offer an obj ect m odel for pr ogram m ing on a Web serv er . • Second, y ou can click t he Web Form s t ab in t he Toolbox t o ex pose Web serv er form cont r ols designed explicit ly for use wit h ASP. NET. These cont r ols ar e r endered as HTML on Web pages, but t hey have pr opert ies, m et hods, and event s associat ed w it h t hem . You can use Web serv er cont r ols on t he ASP.NET Page class inst ances sim ilar ly t o t he way y ou use Windows form cont r ols on form s in Windows applicat ions. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  4. • Third, y ou can use t he it em s on t he Dat a t ab in t he Toolbox t o inv ok e wizards for declar ing and inst ant iat ing ADO.NET obj ect s, such as a dat a adapt er for SQL Server or a dat a set . These ADO.NET obj ect s r eside on a page at design t im e, and t hey can t hus sim plify your code by reducing t he need t o declar e and inst ant iat e obj ect s. See Chapt er 1 for t he discussion of an exam ple t hat dem onst rat es t he use of t hese form s in a Windows applicat ion. This chapt er cont ains supplem ent ar y ASP.NET applicat ions t hat illust rat e t he use of Dat a cont rols on Web pages. HTML cont r ols and Web serv er cont rols bot h represent t ext box es, but t ons, and sim ilar k inds of cont rols. The list of HTML cont r ol it em s m aps t o t he classic HTML for m cont r ols, such as a label, a t ext field, a subm it but t on, and a r eset but t on. HTML cont r ols can r un eit her as classic HTML for m cont rols or as HTML server cont r ols. You need t o designat e a special at t r ibut e ( r unat = " serv er" ) in order for t he it em s on t he Toolbox’s HTML t ab t o be available for pr ogram m ing on a Web serv er. HTML cont rols w it h t he special at t r ibut e set t ing are oft en designat ed HTML serv er cont rols in t he ASP.NET docum ent at ion. You m ust giv e HTML ser ver cont r ols a nam e at design t im e by assigning a value t o t heir I D at t ribut e in order t o r efer ence t hem pr ogr am m at ically on a Web ser ver. Wit hout t he special r unat at t ribut e set t ing, HTML cont r ols pass t heir values along in eit her of t he t wo t radit ional ways: in t he HTTP header or in t he body of a form on an .aspx Web page. I f y ou use t he special at t r ibut e set t ing, y ou can m anipulat e HTML cont r ol propert ies sim ilar ly t o t he way you m anage cont rols on a Windows for m . N ot e The HTML form ’s m et hod at t r ibut e t ells a Web server where t o look for v alues wit h a form on a Web page. The “get ” set t ing for a m et hod at t r ibut e says t o look in t he HTTP header . This is a query st ring appear ing aft er t he URL t o which a Web page navigat es. The “post ” set t ing designat es t he st orage of values in t he body of a Web page. Web serv er cont rols convey HTML t o browsers. Howev er, t he HTML synt ax for t hese cont rols doesn’t m ap in a one- t o- one way t o HTML form cont r ols. For exam ple, t he RadioBut t onList Web serv er cont r ol cont ains t ext inside an HTML t able elem ent . This cont rol doesn’t m ap t o t he HTML Radio But t on cont r ol, alt hough bot h cont r ols can hav e a sim ilar look on a Web page. Select ed Web serv er cont rols include But t on, Label, List Box , Dat aGr id, HyperLink, and about 25 m or e. You can see t he full list of Web serv er cont r ols wit h links for dr illing down furt her int o t he pr opert ies, m et hods, and ev ent s for each one in t he “Web Serv er Cont rols” t opic of t he Visual St udio .NET docum ent at ion. N ot e You can open t he Visual St udio .NET docum ent at ion fr om t he Program s m enu on t he Window s St ar t but t on. Choose Microsoft Visual St udio .NET Docum ent at ion fr om t he Microsoft Visual St udio .NET it em on t he Program s m enu. Use t he Sear ch t ab t o ret ur n a list of it em s m at ching a sear ch crit er ion, such as Web Server Cont r ols. I f y ou have difficult y finding a part icular t opic because t oo m any it em s ret ur n, sort by Tit le by click ing t he Tit le header in t he Sear ch result s window. Then scr oll t hr ough t he it em s, which are now Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  5. list ed in alphabet ical order, t o t he it em you want . Web serv er cont rols and HTML serv er cont rols shar e select ed feat ur es in com m on. For exam ple, one killer feat ure is t he abilit y for form cont rols t o m aint ain t heir values on round- t r ips t o a Web ser ver. This m aint enance of form field values can r equir e a lot of program m ing w it h t radit ional HTML cont rols on HTML form s. How ever, Web serv er cont rols and HTML serv er cont rols prov ide t his feat ur e w it hout any pr ogram m ing. Anot her significant feat ure shared by Web serv er cont rols and HTML ser ver cont r ols is t he abilit y t o use t he validat ion cont r ols t o assess t he cont ent of cont r ols on a form . Validat ion cont r ols enable cert ain validit y t est s, such as whet her t he cont r ol cont ains an ent ry, whet her t he cont r ol has a value in a specified form at , and w het her t he value is in a specified range. Again, no program m ing is necessary for base funct ionalit y. How ev er, lear ning a few pr ogram m ing t ricks for t he validat ion cont rols can enable y ou t o refine t he user exper ience. I st rongly urge y ou t o use Web ser ver cont r ols inst ead of HTML serv er cont rols in all y our ASP.NET applicat ions. As t heir nam es im ply, Web serv er cont r ols run aut om at ically on t he Web serv er . Ther e is no special at t ribut e for you t o set in order t o use t he cont r ols on a Web serv er. Web serv er cont rols are m uch m ore ext ensive in t heir variet y t han HTML serv er cont rols. I n addit ion t o t he st andard HTML cont r ol t ypes, Web serv er cont rols offer a var iet y of specialized cont rols t o facilit at e y our display and m anipulat ion of dat a, including a Dat aGr id cont rol for display ing dat a as a t able. Dev elopers who build solut ions for ent er ing or show ing dat es are likely t o find t he Web serv er Calendar cont rol of special value. This cont r ol enables ent er ing and display ing dat es on a st andard m ont hly calendar display . The general HTML form at for a Web ser ver cont r ol appears her e. The asp prefix denot es t he cont r ol as a Web serv er cont rol. The cont rolnam e param et er specifies t he t ype of cont rol ( for exam ple, label) . The at t r ibut es param et er corr esponds t o a list of propert y set t ings. ASP.N ET D e sign I n t e r f a ce s I have been developing Web solut ions pr im arily wit h Micr osoft t echnology since approx im at ely 1995, and t he ASP.NET design int erface is by far m y fav or it e over t hat t im e span. This is because t he ASP.NET design int erface offers you t he flex ibilit y of dev eloping a Web applicat ion v ery m uch as y ou cr eat e Windows solut ions wit h Visual Basic .NET. I t leav es m e fr ee t o focus on m y solut ion inst ead of being dist ract ed by Web layout dev elopm ent issues. I n ot her w ords, ASP.NET prov ides a design env ir onm ent t hat m ak es m e feel as t hough I ’m cr eat ing a t ypical Windows solut ion— except it ’s for t he Web. ( See Chapt er 8 for m or e coverage on t his point .) Nonet heless, t he ASP.NET design env ir onm ent st ill has som e unique feat ur es, which w ill be covered in t his sect ion. Aft er init ially cr eat ing a new ASP.NET proj ect ( as described in t he preceding sect ion) , y ou are confront ed w it h t he HTML Designer, which displays a blank Web lay out page. By default , t his page will hav e t he filenam e WebFor m 1.aspx. The first point t o not e is t hat t he t ab for t he page has t wo cont rols at it s bot t om . The page opens w it h t he Design cont r ol select ed ( unless you change t he default set t ing) , which pr esent s a graphical v iew of t he page. Click ing t he HTML cont r ol displays t he HTML code behind t he page. I n ot her words, t he HTML Designer offers t wo v iews for each page— a Design v iew for graphical dev elopm ent of a page and an HTML code view for program m at ic design of a page. When y ou look at t he page in HTML v iew, you’ll see t hat it st art s w it h an @Page dir ect iv e. I n t his dir ect ive ar e set t ing assignm ent s t hat y ou should t ypically not edit . Next t her e is a docum ent declarat ion declaring t he page t o be an HTML 4.0 docum ent . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  6. Aft er t he t w o prelim inar y declarat ion st at em ent s, t he HTML code window displays an ht m l t ag. A m at ching / ht m l t ag ends t he docum ent . Ot her HTML t ags nest bet ween t hese beginning and ending t ags for t he HTML cont ent w it hin a docum ent . Tw o set s of m at ching t ags nest direct ly beneat h t he ht m l and / ht m l t ags. The cont ent bet ween t he head and / head t ags is m ost ly boilerplat e m at er ial rout inely prepar ed by Visual St udio for all .aspx page files t hat it generat es. Howev er, t he t it le and / t it le t ags cont ain t he t it le t hat appears in t he t it le bar of a Web browser w indow w hen t he br owser display s t he page. You can edit a page’s t it le eit her from t he HTML code w indow or t he Propert ies w indow for t he docum ent . Changes in eit her locat ion updat e t he ot her locat ion aut om at ically . The next pair of nest ed t ags wit hin t he ht m l and / ht m l t ags ar e t he body and / body t ags. Unless you change t he default set t ings, t he body t ag will have an MS_POSI TI ONI NG at t r ibut e set t ing of Gr idLay out . This handy set t ing let s you drag and dr op cont r ols around a Web page j ust as on a Windows form . The MS_POSI TI ONI NG at t r ibut e set t ing corr esponds t o t he pageLay out pr opert y set t ing in t he Propert ies window for t he docum ent . The default set t ing for t he pageLay out set t ing m at ches t he MS_POSI TI ONI NG at t ribut e set t ing of Gr idLayout . Choosing t he ot her pr opert y set t ing of FlowLayout for t he pageLay out propert y r em oves t he MS_POSI TI ONI NG at t ribut e from t he HTML code window. This alt ernat iv e layout set t ing allows y ou t o posit ion cont rols on a Web page as you do cont ent on a t ypical word processing docum ent . This is t he t radit ional HTML way of posit ioning cont r ols on a page, and it prov ides y our gr eat est com pat ibilit y w it h br owser t ypes— especially older br owser t y pes t hat don’t support absolut e posit ioning. How ev er , y ou giv e up t he convenience of being able t o drag and drop cont r ols on a Web page. The form and / form t ags r eside w it hin t he body t ags. All t he cont rols on a Web page appear w it hin t he form and / form t ags. I will discuss t hese t ags next as I r ev iew t he page design for our WebApplicat ion1 proj ect , w hich was init ially discussed in Chapt er 8. N ot e The WebApplicat ion1 sam ple, like m ost of t he sam ples in t his chapt er , exist s as t wo folder s. Bot h folders hav e t he nam e WebApplicat ion1. One cont ains j ust t wo files in it s r oot . One of t hese files is WebApplicat ion1.sln. The folder cont aining t his file belongs in t he dir ect ory t hat your com put er uses for st or ing Visual Basic .NET Windows solut ions. You can open t he WebApplicat ion1 solut ion in Visual St udio by choosing Open Solut ion from t he File m enu and select ing WebApplicat ion1.sln. You m ay need t o br owse t o t he folder cont aining WebApplicat ion1.sln befor e being able t o select it . The second folder cont ains WebFor m 1.aspx in it s root . This folder belongs in t he ww wroot direct ory of t he I net pub folder on t he com put er fr om which you will be r unning t he applicat ion. You can open t he Web page by browsing ht t p: / / < webserver> / WebApplicat ion1/ WebFor m 1.aspx . Recall t hat t he WebApplicat ion1 proj ect fr om Chapt er 8 cont ains t wo cont r ols: a but t on and a label. Click ing t he but t on causes t he label t o show “Hello Wor ld.” Figur e 11- 2 rev eals t he but t on cont r ol above t he label cont rol in Design view for WebApplicat ion1’s WebForm 1.aspx file. Bot h cont rols are Web serv er cont rols. I select ed t hem fr om t he Web Form s t ab of t he Toolbox. When y ou add a cont r ol from t he Toolbox t o a Web page, y ou can select it in t he Toolbox and t hen size t he cont rol by dr agging it out on y our Web page. Alt ernat iv ely, y ou can right - click t he cont rol t ype in t he Toolbox and choose Copy . Then r ight - click in Design v iew Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  7. for t he Web page, and choose Past e. This adds t he cont rol wit h pr econfigur ed size set t ings in t he upper left corner of t he page. I f your docum ent has a Gr idLayout set t ing for it s pageLayout pr opert y , y ou can t hen j ust drag t he cont r ol t o it s desired locat ion. Figur e 11- 2 shows t he label and but t on cont r ols w it h t heir preconfigur ed size set t ings. Figu re 1 1 - 2 . Th e ASP.N ET D e sign vie w for W e bFor m 1 .a sp x in t h e W eb Applica t ion 1 pr oj e ct . Figur e 11- 2 shows sev eral t oolbars. All t he cont rols on t he bot t om row, aft er t he first t wo, belong t o t he Layout t oolbar. I f t his t oolbar isn’t v isible, y ou can m ak e it appear in t he usual way for Windows applicat ions— r ight - click any t oolbar, and select t he one y ou want ( Layout ) from t he cont ext m enu. ( You can also select Toolbars from t he View m enu and select t he appropriat e t oolbar from t he list . ) The cont r ols on t his t oolbar can m ake fast work of t ypical form layout design t asks, such as aligning, sizing, and spacing cont rols. Not ice also in t he figur e t hat t he Web page appears wit h a gr id. The default set t ing is for cont rols t o snap t o t he grid m arks as you m ov e cont r ols around t he form . I f you pr efer m or e granular posit ioning or you don’t want t o show a gr id, you can achieve t hese result s by choosing Opt ions from t he Tools m enu. I n t he Opt ions dialog box , Open t he HTML Designer folder and select Display. The right port ion of t he dialog box t hen rev eals cont r ols for set t ing t he Snap To Gr id and Show Gr id opt ions. This port ion of t he Opt ions dialog box also includes t ext boxes for y ou t o specify t he spacing bet ween grid m ark s in Design v iew. You can also cont r ol t he appearance of t he grid by r ight - click ing any blank ar ea of a page in Design view and choosing Pr opert ies. I f t he pageLay out propert y for a page is Gr idLayout , t he General t ab of t he DOCUMENT Propert y Pages dialog box exposes t he Show Gr id check box. Clearing t he check box st ops t he grid fr om appear ing, but cont rols st ill snap t o t he gr id w hen y ou m ove t hem . I f you swit ch fr om Design v iew t o HTML v iew, you can see t he for m and / form t ags inside bounding body and / body t ags. Just as t he form and / form t ags are wit hin body and / body t ags, so ar e t he t ags for t he but t on and label cont r ols wit hin t he t ags for t he form . You can see fr om t he following HTML ex cer pt for t he WebForm 1.aspx page t hat t he but t on and label cont r ols ar e Web serv er cont r ols Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  8. because t heir init ial t ag begins wit h t he asp pr efix ( asp: But t on and asp: Label) . Aft er t he t ag designat ion init iat ing a cont r ol, a series of at t r ibut e set t ings defines t he cont rol feat ures. The at t ribut e set t ings are so num er ous t hat t hey cause t he cont r ol t ag t o w rap t o a second line. The id at t r ibut e indicat es t he nam e by w hich your pr ogram can refer t o t he cont r ol. The TOP at t ribut e designat es how far down, in pix els, a cont r ol is fr om t he t op page border . Not ice t hat t he label cont r ol is 40 pix els fart her dow n t he page t han t he but t on. The but t on cont rol is 7 pix els closer t o t he page’s left border t han t he label cont r ol.
  9. When y ou choose t o v iew t he code for an em pt y Web page, y ou w ill see j ust one procedur e, t he Page_Load ev ent pr ocedur e. This procedur e w ill cont ain a com m ent t hat r eads, “Put user code t o init ialize t he page here.” I r et ained t his com m ent in Figure 11- 3 for y our r efer ence. The Page_Load ev ent pr ocedur e wor ks m uch like t he For m _Load ev ent pr ocedur e for Windows applicat ions. You can m ak e assignm ent s t hat need t o t ak e place befor e a user int eract s wit h a Web page. I n t he WebApplicat ion1 sam ple, t he Page_Load ev ent pr ocedur e assigns “Click m e” t o t he Text propert y for But t on1 and clears t he Tex t pr opert y for Label1. The But t on1_Click event procedur e can be included because of t he Prot ect ed Wit hEv ent s declarat ion at t he t op of t he m odule. Cr e a t in g a n d Ru nn in g ASP.N ET Solu t ion s Building Web solut ions wit h ASP.NET can be v ery st raight forward for Visual Basic dev elopers. This sect ion includes several sam ples t o illust rat e basic Web design issues. You st art w it h a review of t echniques for com piling and v iewing Web pages. This rev iew leads t o a sam ple t hat dr ills down on t echniques for m anaging t he appearance of cont rols on a Web page. I n t he pr ocess, you lear n synt ax issues for t he Page_Load ev ent pr ocedur e as w ell as ev ent pr ocedur es for cont r ols on a Web page. Anot her pair of sam ples dem onst rat es how t o const ruct a m ult ifunct ion calculat or. These sam ples illust rat e t echniques for wor king w it h t ext boxes on a Web page as well as how t o opt im ize pages for different t ypes of browsers. The sect ion concludes w it h a sam ple t hat aut om at ically det ect s t he t ype of t he br owser request ing a page and t ransfers cont rol t o a page opt im ized for t hat br owser t ype. Com pilin g a n d V ie w in g W e b Pa ge s I f you inst all t he folder wit h t he WebFor m 1.aspx file for WebApplicat ion1 in t he wwwr oot folder for t he Web serv er on your local com put er, you can open t he solut ion in a browser wit h t he follow ing URL: ht t p: / / localhost / WebApplicat ion1/ WebForm 1.aspx Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  10. This URL designat es t he local Web ser ver by specifying localhost . I f you hav e t he WebApplicat ion1 folder cont aining WebForm 1.aspx inst alled on a differ ent com put er running I I S and t he .NET Fram ew ork , you can open t he Web page in a browser w it h t he follow ing URL. Serv ernam e t y pically specifies t he nam e of t he com put er running t he Web serv er. ht t p: / / < serv er nam e> / WebApplicat ion1/ WebForm 1.aspx I recom m end r unning pages fr om a br owser . I n fact , if y ou are sur e t hat your applicat ion w ill have t o be r un by users w it h different browser t ypes, y ou should t est your Web pages w it h as m any of t hese browser t ypes as possible. You m ight ev en consider t ry ing out your Web pages wit h different set t ings. Som e set t ings can affect how t he page works in a browser— part icular ly if t he page t aps any client - side ( t his m eans browser ) funct ionalit y . I will cover exam ples of t hese issues lat er in t his chapt er . You m ust com pile any changes t o a page before you can v iew t hose changes in a browser. Therefor e, for init ial t est ing purposes, you m ight care t o open your Web pages fr om w it hin Visual St udio so y ou can m or e easily debug y our solut ions. You can r ight - click a page t hat you want t o open in Solut ion Explor er and choose one of t w o m enu it em s t o v iew t he page. I f y ou hav en’t m ade any changes t o t he page since t he last build, y ou can select View I n Br owser . This opens a Browse window w it hin Visual St udio t hat sim ulat es t he appearance of t he page as if it wer e in a br owser. I f y ou edit ed t he page’s layout or code behind t he page since t he last t im e t he page was view ed, choose Build And Browse from t he cont ext m enu when y ou right - click t he page in Solut ion Explor er. This r ecom piles t he solut ion w it h any changes t hat y ou m ade befor e display ing t he page w it hin t he Visual St udio Browse w indow . No m at t er w hich approach you use t o open a Browse window , t he w indow appears on a separ at e t ab lik e t he ones for t he Web page’s layout and t he code behind t he page. Right - click wit hin t he Br owse w indow for a select ion of com m on br owser com m ands, such as Back, Forward, and Refr esh Br owser. Figur e 11- 4 shows WebForm 1.aspx fr om WebApplicat ion1 when it init ially opens in I nt er net Explor er and aft er a click of t he but t on labeled Click Me. One click of t he but t on causes a label below t he but t on t o show Hello Wor ld. Repeat edly click ing t he but t on seem s t o hav e no effect , alt hough t he Page_Load and But t on1_Click ev ent pr ocedur es operat e for each click. This is because each click ret ur ns t he Web page back t o t he serv er for processing. The r eason not hing appears t o change is t hat t he label’s Text pr opert y get s set t o t he sam e value on each ret urn t o t he server as a result of a click of But t on1. Figu re 1 1 - 4 . Th e t op w in dow sh ow s h ow W e bForm 1 .asp x fr om W eb Applicat ion 1 a ppea r s w h e n it in it ia lly loa ds. Th e bot t om w in dow sh ow s t h e W e b pa ge a ft e r a click of t h e bu t t on . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  11. Re m e m be r in g t he St a t e of a Pa ge One w ay t o im pr ov e on t he operat ion of t he page in WebApplicat ion1 is t o k eep t rack of whet her a br ow ser opens a page for t he first t im e or whet her a browser sends a page back t o t he serv er t hat is alr eady open w it hin t hat br owser. You can addit ionally coordinat e t his know ledge w it h t he appearance of t he page. This w ill giv e users fr esh inform at ion t hat reflect s t he st at e of t he page— not j ust t he sam e inform at ion on ev er y click. The Post backSam ple proj ect has a Web page nam ed WebForm 1.aspx t hat r eflect s four separat e st at es. Furt herm ore, alt hough t he page address, WebFor m 1.aspx in t he Post backSam ple folder, st ays t he sam e, t he appearance of t he page’s form changes wit h each successive click. The page’s appearance indicat es t he st at e of t he form on t he page. When t here are no m or e st at es t o show, t he page m ak es all but t ons inv isible so t hat a user cannot r epeat edly click a but t on wit hout anyt hing happening. N ot e Like t he WebApplicat ion1 sam ple, t he Post back Sam ple exist s Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  12. as t wo separat e folders. Place t he folder t hat cont ains WebFor m 1.aspx in t he wwwr oot direct ory of t he I net pub folder for t he com put er ser ving as a Web ser ver. Place t he folder wit h Post backSam ple.sln in t he dir ect ory st oring your Visual St udio pr oj ect s. Figur e 11- 5 shows how t he WebForm 1.aspx page appears for each successive st at e. The t op window shows t he page w hen a user init ially nav igat es t o t he page. This init ial st at e for t he Post backSam ple applicat ion has t he sam e appearance as t he init ial page for t he WebApplicat ion1 solut ion. Aft er a user clicks t he but t on labeled Click Me, t he page r et ur ns saying, “Hello Wor ld” , but t he page changes it s look in ot her ways as well. Specifically, t he Post backSam ple applicat ion m akes But t on1 inv isible. I n addit ion, t he applicat ion shows a new but t on, But t on2, w it h a Text pr opert y of “Hello Show ed” . By clicking t his second but t on, t he user causes t he Web page t o t rav el t o t he serv er and back t o t he browser . While at t he Web serv er, t he layout of t he page changes again. This t im e, t he but t on w it h a label of Hello Show ed changes it s label t o “ Click for adv ice”. I n addit ion, Label1 appears wit h a new Text propert y of “ Get busy.” Clicking t he but t on one m or e t im e changes t he appearance t o t he w indow at t he bot t om of Figur e 11- 5. I n t his final st at e, no but t ons ar e v isible for a user t o click . I n addit ion, t he code behind t he page has no m or e dist inct appearances left t o present . I n addit ion t o m aking bot h but t ons inv isible, t he Text pr opert y for Label1 changes t o “ St ay busy.” Figu r e 1 1 - 5 . A sin gle W e b pa ge , W e bFor m 1 .a sp x in t h e Post b ack Sam ple pr oj ect , pr ese n t s fou r differ e n t a pp ea ra n ce s de pe ndin g on t h e st at e of t h e W e b pa ge a n d t h e con t r ols on it . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  13. Figur e 11- 6 shows t he Design v iew of WebFor m 1.aspx in t he Post backSam ple proj ect . Not ice t hat it cont ains t w o but t ons and a label ( Label1) . I dragged t he size of But t on2 so t hat it is slight ly w ider t han But t on1. I f y ou ev er pr ogram m ed wit h ASP, y ou’ll appreciat e how r em arkable t he sim plicit y of t he page is. Not ice specifically t hat no code is m ix ed in w it h t he page. Figu re 1 1 - 6 . Th e D esign vie w of t h e W e b pa ge t h a t a pp ea r s in t h e fou r diffe r en t st at e s sh ow n in Figu re 1 1 - 5 . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  14. Because t he lay out for t he Web page is so basic, t he cont rol of t he page’s appearance m ust be in t he logic of t he code behind t he page. Before focusing on t he specific code behind t he page, I want t o int roduce t he I sPost back pr opert y for a page. This propert y t ells t he serv er whet her t he page is loading init ially or as t he r esult of t he user clicking a cont r ol on t he page t hat sends t he page back t o t he serv er. I f t he I sPost back propert y is False, t he page is opening init ially . I f t he I sPost back propert y is True, t he page is being sent back t o t he ser ver by t he user click ing on a cont rol. The logic of t he Post backSam ple applicat ion t akes advant age of t he I sPost back propert y t o help cont r ol t he appearance of t he Web page. The follow ing list ing shows t he t hree ev ent pr ocedures m anaging t he appearance of WebForm 1.aspx in t he Post backSam ple proj ect . The list ing com m ences wit h t he Page_Load ev ent pr ocedur e. This pr ocedur e fir es each t im e t he page opens— whet her init ially or ot herw ise. However, w it hin t he Page_Load ev ent , different code execut es depending on t he value of t he I sPost back propert y and t he Text propert y set t ing for But t on2. I f t he I sPost back propert y is False, t he procedur e m akes t hr ee pr opert y assignm ent s t hat m ake t he page appear lik e t he t op window in Figure 11- 5. The ElseI f and Else clauses for t he I f st at em ent handle cases in w hich t he Web page r et ur ns t o t he serv er aft er opening init ially . The ElseI f clause specifically handles t he case in w hich a page r et ur ns t o t he serv er wit h t he But t on2 Text propert y equal t o “Hello Show ed” . I f t he page ret urns t o t he serv er w it h a differ ent value for t he But t on2 Tex t pr opert y, t he I f st at em ent rout es cont r ol t o t he Else clause. The But t on1_Click ev ent fir es when t he user clicks But t on1. Ther e is only one chance t o do t his because t he Click ev ent pr ocedur e m akes t he but t on inv isible. I n addit ion, t he procedure assigns “Hello Wor ld” and “Hello Show ed” as values t o t he Text pr opert y for Label1 and But t on2, respect ively . The But t on2_Click ev ent procedure can fire in eit her of t w o circum st ances, and it needs t o r espond differ ent ly t o each case. Ther efor e, it uses an I f…Then…ElseI f st at em ent t o cont r ol w hich st at em ent t o ex ecut e. When Label1 shows “Get busy.”, t he procedur e changes t he Text pr opert y for But t on2 t o “Click for adv ice”. I f t he label shows “ St ay busy.” , t he ElseI f clause operat es t o m ak e But t on2 inv isible. Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ’If it is a first-time presentation, then ’set like WebApplication1, or ’if it is a postback with Hello Showed button, ’then change message to Get busy, or else ’change message to Stay busy. If IsPostBack = False Then Button1.Text = “Click me" Button2.Visible = False Label1.Text = “" ElseIf IsPostBack = True And _ Button2.Text = “Hello Showed” Then Label1.Text = “Get busy." Else Label1.Text = “Stay busy." Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  15. End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ’Make label say Hello World. Label1.Text = “Hello World" ’Make Text for Button2 read Hello Showed and ’make Button2 visible. Button2.Text = “Hello Showed" Button2.Visible = True ’Make Button1 invisible. Button1.Visible = False End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ’If Label1 says Get busy, show Button2 ’with a Text property of Click for advice, ’else make Button2 invisible. If Label1.Text = “Get busy.” Then Button2.Text = “Click for advice" ElseIf Label1.Text = “Stay busy.” Then Button2.Visible = False End If End Sub A M u lt ifu n ct ion Ca lcu la t or W e b Pa ge One of t he t r uly cool feat ur es of form s on pages in ASP.NET is t hat t he propert y values for cont r ols persist bet ween r ound- t r ips t o t he serv ers. The pr eceding sam ple didn’t highlight t his feat ur e because t he whole point of t hat sam ple was t o show how t o change t he values of cont r ols on successive round- t r ips t o t he serv er. This sam ple, t he WebCalculat or pr oj ect , t akes advant age of aut om at ic persist ence of cont rol propert y v alues dur ing t he round- t r ip from a br owser t o a Web serv er and back again. I f y ou did m uch ASP coding, y ou m ay r ecall t hat it was necessary t o wr it e code if you w ant ed cont rols t o display t he sam e values on t he way back fr om a server as on t he way up t o a ser ver. The WebCalculat or proj ect highlight s t he aut om at ic persist ence of cont r ol values by let t ing users ent er v alues in t w o t ext boxes. When t he user clicks one of four but t ons for a t ype of ar it hm et ic bet w een t he v alues appear ing in t he t ex t box es, t he page goes off t o t he serv er. The procedur es for perform ing t he ar it hm et ic wor k dir ect ly w it h t he Text propert y for t he t ext box cont rols on t he Web page. I n ot her words, t he values pass t o t he serv er v ia t he t ext box cont rols. Wit h t radit ional HTML form s, t he values pass t o t he ser ver as nam e and value pairs. The nam e r epresent s t he cont r ol nam e, and t he value repr esent s t he ent ry in t he cont r ol. I f values need t o appear in a page when it ret ur ns t o a browser from a serv er on a t radit ional HTML form , you m ust wr it e code t o r eassign t he values t o cont r ols on t he page t he serv er sends back t o t he br owser. The WebCalculat or proj ect is a four - funct ion calculat or. Each funct ion has it s ow n but t on w it h a Text pr opert y set t ing repr esent ing t he t ype of calculat ion it Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  16. perform s— nam ely, + , - , * , and / . Users ent er v alues in t he first t wo t ex t box es on t he Web page. Users access t his proj ect by navigat ing t o WebCalculat or.aspx in t he WebCalculat or pr oj ect . When I first creat ed t he proj ect , ASP. NET assigned WebForm 1.aspx as t he st at page nam e for t he proj ect . However, I r ev ised t he nam e t o WebCalculat or.aspx in Solut ion Explor er using t he t echnique described prev iously . When t he page goes t o t he serv er, it per form s t he calculat ion denot ed by t he but t on a user clicks. A sim ple event procedur e for each but t on handles t his. Each of t he ev ent procedur es for t he four but t ons calls anot her pr ocedur e t hat form at s t he value r et ur ned t o t he br owser in t he t hird t ext box on t he page. This form at t ing pr ocedure assigns a color t o t he t ext box For eColor propert y based on t he value r et urned and m akes t he font bold. Figur e 11- 7 shows t he WebCalculat or pr oj ect w ork ing for a pair of values in t he first and second t ext boxes. The t op w indow shows t he WebCalculat or.aspx page befor e a user click s one of t he four funct ion but t ons. Not ice t hat t he user ent er ed values in t he first and second t ext box es ( - 2.2 and 3.3) . The t hird t ext box is em pt y. The bot t om w indow shows t he page t hat ret urns from t he Web serv er aft er t he user click ed t he bot t om but t on on t he for m wit h a Text proper t y equal t o / . I n t he bot t om w indow , t he applicat ion populat es t he t hird t ext box w it h t he quot ient of - 2.2 div ided by 3.3. The t ext box displays t he result t o single- precision accuracy. Because t he value is negat ive, it appears in r ed w it hin t he browser w indow. I n addit ion, t he value in t he t hird t ext box appears in a bold font . Figu r e 1 1 - 7 . Th e W eb Ca lcu la t or .a sp x pa ge b e for e an d a ft er a t rip t o t h e W eb se rve r. Th e u se r in vok ed t h e r ou n d - t rip t o t h e se r ve r by click in g t h e b ot t om bu t t on ( / ) . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  17. The but t ons on t he page hav e I D propert y set t ings of But t on1 t hrough But t on4 from t he t op but t on t o t he bot t om but t on. The cor e of t he applicat ion is t he ev ent procedur es behind each of t hese but t ons. The m odule for t he page st art s by declaring a single- pr ecision var iable nam ed sgn1. This var iable st ores t he r esult of t he calculat ion perfor m ed on t he cont ent s of Text Box1 and Text Box2. Because t he m odule declar es sgn1 as a Single dat a t ype and it s input v alues ar e conv ert ed from a St ring dat a t y pe t o a Single dat a t ype, t he result of t he ar it hm et ic com put at ion has a single dat a t ype. However, t he Text propert y of Text Box3 requir es a St r ing dat a t ype. Therefor e, t he assignm ent of sgn1 t o a Text pr opert y inv okes t he ToSt r ing m et hod t o convert a num eric value t o a st ring. Each of t he Click ev ent procedur es for t he but t ons inv ok es t he ColorTex t I nText Box3 pr ocedur e. This pr ocedur e has an I f st at em ent w it h Then, ElseI f, and Else clauses. The I f st at em ent assigns one of t hr ee colors t o Text Box3 based on t he value in sgn1. Posit iv e values r esult in a For eColor pr opert y assignm ent for Text Box 3 of gr een. Negat ive values lead t o a red For eColor propert y assignm ent . I f t he sgn1 value is 0, t he procedur e assigns black as t he for eground color for Tex t Box3. No m at t er w hat color t he pr ocedur e assigns t o t he Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  18. ForeColor propert y for Text Box3, t he procedure concludes by m ak ing t he font bold. Dim sgn1 As Single Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ’Add text boxes. sgn1 = CSng(TextBox1.Text) + CSng(TextBox2.Text) TextBox3.Text = sgn1.ToString ColorTextInTextBox3() End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ’Subtract text boxes. sgn1 = CSng(TextBox1.Text) - CSng(TextBox2.Text) TextBox3.Text = sgn1.ToString ColorTextInTextBox3() End Sub Private Sub Button3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button3.Click ’Multiply text boxes. sgn1 = CSng(TextBox1.Text) * CSng(TextBox2.Text) TextBox3.Text = sgn1.ToString ColorTextInTextBox3() End Sub Private Sub Button4_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button4.Click ’Divide text boxes. sgn1 = CSng(TextBox1.Text) / CSng(TextBox2.Text) TextBox3.Text = sgn1.ToString ColorTextInTextBox3() End Sub Sub ColorTextInTextBox3() ’Assign forecolor to TextBox3 based on result value. If sgn1 > 0 Then TextBox3.ForeColor = Drawing.Color.Green ElseIf sgn1 < 0 Then TextBox3.ForeColor = Drawing.Color.Red Else TextBox3.ForeColor = Drawing.Color.Black End If ’Make font bold to highlight assignment. TextBox3.Font.Bold = True Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  19. End Sub A M u lt ifu n ct ion Ca lcu la t or in a Ta ble All t he sam ples in t his chapt er t o t his point display Web pages in a Microsoft I nt er net Explor er browser . I t est ed t he pages w it h t he I nt er net Explorer 5 and I nt er net Explor er 6 browsers. How ev er , m any visit ors browse I nt ernet sit es w it h non–I nt er net Explor er browsers. I am t he Webm ast er at www.Program m ingMSAccess.com , a sit e t hat cat ers t o t he int erest s of Micr osoft Access, Micr osoft SQL Ser ver, and Visual Basic dev elopers. This sit e ex plicit ly t arget s t he int erest s of t hose loyal t o Micr osoft product s, and it has done t his for about four y ears as I writ e t his chapt er. Nev ert heless, about 15 percent of t he visit ors t o t he sit e br ow se pages w it h a Net scape br owser. The ov erw helm ing m aj or it y of t he Net scape br owser sessions are conduct ed wit h a Net scape 4.x browser. As st at ed pr ev iously, I fully believ e in support ing one br owser. My personal preference is for t he m ost recent v ersion of t he I nt er net Explorer br owser because it provides t he lat est feat ur es from a prov en soft w ar e leader— Micr osoft . When dev eloping int ranet and ext ranet solut ions, you can m andat e a single browser for t he solut ion. When dev eloping I nt er net solut ions, t he guidelines for deciding w hich br owser ( or how m any br owsers) t o support can be m or e com plex because y ou cannot m andat e t hat users browse your sit e w it h a specific browser . Ther efor e, for I nt er net solut ions, you hav e at least a couple of opt ions. First , you can pr om inent ly st at e in browser- neut ral t ext t hat a page is opt im ized for one browser. I f users want t o v iew t he page, t hey can inst all t he browser for w hich t he page is opt im ized. Second, y ou can dev elop different pages for differ ent browsers. This sect ion illust rat es t he second approach w it h t he sam ple from t he preceding sect ion. I n deciding w het her t o prepare m ult iple v ersions of a page for differ ent browser t ypes, t he first st ep is t o v iew t he page in all t he t arget browsers t hat y ou plan t o support . For exam ple, Figur e 11- 8 shows t he WebCalculat or.aspx page in a Net scape 4.01 browser. Not ice t hat t he page doesn’t look lik e t he w indows in Figur e 11- 7. The prim ar y r eason for t he div ergence in appearance is t hat t he Net scape br owser doesn’t support absolut e posit ioning. ASP.NET uses t his feat ur e t o enable t he posit ioning of cont rols on a Web page w it h drag- and- dr op t echniques. Figu r e 1 1 - 8 . Th e W e bCa lcu la t or .a sp x pa g e in a N e t scap e 4 .0 1 br ow se r . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  20. Many t radit ional Web developers hav e exper ience using t ables t o posit ion cont rols on a Web page. When y ou posit ion cont rols by placing t hem inside t able cells, y ou don’t need t o r ely on absolut e posit ioning cont r ol pr opert y set t ings t o designat e t he locat ion of a cont r ol on a form . By using a t able inst ead of absolut e posit ion cont r ol set t ings, you can dev elop a page t hat is m uch m ore likely t o appear sim ilar in bot h I nt ernet Explor er and Net scape browsers. The t r ick t o achiev ing sim ilar result s in differ ent br owsers by posit ioning cont r ols in t ables is t o set t he pageLay out propert y t o FlowLay out . Recall t hat t his set t ing causes cont ent t o appear on a Web page in t he flow pat t ern of a word pr ocessor inst ead of t he classic Visual Basic drag- and- drop st yle. I built anot her version of t he WebCalculat or .aspx page in t he WebCalculat or proj ect t o dem onst rat e t he st eps for creat ing a calculat or in a t able. St art by creat ing a new Web page in t he WebCalculat or proj ect . Choose Proj ect , Add Web Form fr om t he Visual St udio m ain m enu in Design v iew. I n t he Add New I t em dialog, choose t he Web Form t em plat e, nam e t he new Web page WebCalculat orI nTable.aspx, and click Open. I f y ou ar e using t he sam e proj ect and y ou want t o duplicat e m y st eps, nam e t he new Web page som et hing else, for exam ple, My WebCalculat orI nTable.aspx. Set t he pageLay out pr opert y for t he docum ent t o FlowLay out ( as descr ibed in t he “ASP.NET Design I nt er faces” sect ion) . Add a t able w it h four colum ns and t hr ee r ows t o t he WebCalculat orI nTable.aspx Web page. St art by choosing I nsert and t hen Table from t he Table m enu. Set t he Colum ns box t o 4 and click OK on t he I nsert Table dialog box, leaving t he default set t ing of 3 for t he Row s box . Next em bed a new t able in t he second colum n of t he original t able’s t hird row. The em bedded t able should hav e one colum n of four rows w it h a widt h of 27 pix els. Aft er posit ioning t he cursor w her e you w ant t he em bedded t able, choose Table, I nsert , Table. Set t he Rows box t o 4 and t he Colum ns box t o 1. Assign 27 t o t he Widt h box . Then click OK. Next copy t he t ext box and but t on cont r ols from t he WebCalculat or.aspx page t o t he WebCalculat orI nTable.aspx page. You can also copy t he label w it h a Text propert y of “Web Calculat or”. Ar range t he lay out so t hat it looks lik e Figur e 11- 9. I achiev ed t his look w it h a sequence of copy - and- past e operat ions fr om t he WebCalculat or. aspx page t o t he WebCalculat orI nTable.aspx page. No ot her operat ions wer e necessary. N ot e Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

CÓ THỂ BẠN MUỐN DOWNLOAD

Đồng bộ tài khoản