




免費(fèi)預(yù)覽已結(jié)束,剩余13頁(yè)可下載查看
下載本文檔
版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
東北石油大學(xué)本科畢業(yè)設(shè)計(jì)英文文獻(xiàn)及翻譯 學(xué)院計(jì)算機(jī)與信息技術(shù)學(xué)院班級(jí)計(jì)科07-1班學(xué)號(hào)070702140124姓名王東指 導(dǎo) 教 師袁文翠職 稱(chēng)副教授東北石油大學(xué)本科畢業(yè)設(shè)計(jì)(英文文獻(xiàn)及翻譯)ASP.NET 技術(shù)1.構(gòu)建 ASP.NET 頁(yè)面ASP.NET 和ASP.NET結(jié)構(gòu)ASP.NET 是微軟.NET framework整體的一部分, 它包含一組大量的編程用的類(lèi),滿(mǎn)足各種編程需要。 在下列的二個(gè)部分中, 你如何學(xué)會(huì) ASP.NET 很適合的放在.NET framework, 和學(xué)會(huì)能在你的 ASP.NET 頁(yè)面中使用語(yǔ)言。.NET類(lèi)庫(kù)假想你是微軟。 假想你必須支持大量的編程語(yǔ)言-比如 Visual Basic 、 C# 和 C+. 這些編程語(yǔ)言的很多功能具有重疊性。 舉例來(lái)說(shuō),對(duì)于每一種語(yǔ)言,你必須包括存取文件系統(tǒng)、與數(shù)據(jù)庫(kù)協(xié)同工作和操作字符串的方法。此外,這些語(yǔ)言包含相似的編程構(gòu)造。 每種語(yǔ)言,舉例來(lái)說(shuō),都能夠使用循環(huán)語(yǔ)句和條件語(yǔ)句。 即使用 Visual Basic 寫(xiě)的條件語(yǔ)句的語(yǔ)法不與 用C+ 寫(xiě)的不一樣,程序的功能也是相同的。最后,大多數(shù)的編程語(yǔ)言有相似的數(shù)據(jù)變量類(lèi)型。 以大多數(shù)的語(yǔ)言,你有設(shè)定字符串類(lèi)型和整型數(shù)據(jù)類(lèi)型的方法。舉例來(lái)說(shuō), 整型數(shù)據(jù)最大值和最小值可能依賴(lài)語(yǔ)言的種類(lèi),但是基本的數(shù)據(jù)類(lèi)型是相同的。對(duì)于多種語(yǔ)言來(lái)說(shuō)維持這一功能需要很大的工作量。 為什么繼續(xù)再創(chuàng)輪子? 對(duì)所有的語(yǔ)言創(chuàng)建這種功能一次,然后把這個(gè)功能用在每一種語(yǔ)言中豈不是更容易。.NET類(lèi)庫(kù)不完全是那樣。 它含有大量的滿(mǎn)足編程需要的類(lèi)。舉例來(lái)說(shuō),.NET類(lèi)庫(kù)包含處理數(shù)據(jù)庫(kù)訪(fǎng)問(wèn)的類(lèi)和文件協(xié)同工作,操作文本和生成圖像。 除此之外,它包含更多特殊的類(lèi)用在正則表達(dá)式和處理Web協(xié)議。.NET framework,此外包含支持所有的基本變量數(shù)據(jù)類(lèi)型的類(lèi),比如:字符串、整型、字節(jié)型、字符型和數(shù)組。最重要地, 寫(xiě)這一本書(shū)的目的, .NET類(lèi)庫(kù)包含構(gòu)建的 ASP.NET 頁(yè)面的類(lèi)。然而你需要了解當(dāng)你構(gòu)建.NET頁(yè)面的時(shí)候能夠訪(fǎng)問(wèn).NET framework 的任意類(lèi)。理解命名空間正如你猜測(cè)的, .NET framework是龐大的。 它包含數(shù)以千計(jì)的類(lèi)(超過(guò) 3,400) 。幸運(yùn)地,類(lèi)不是簡(jiǎn)單的堆在一起。.NET framework的類(lèi)被組織成有層次結(jié)構(gòu)的命名空間。ASP Classic Note在先前的ASP中,你僅僅能夠訪(fǎng)問(wèn)五個(gè)標(biāo)準(zhǔn)類(lèi)。相比之下 ASP.NET 提供超過(guò) 3,400個(gè)類(lèi)!一個(gè)命名空間包含一組邏輯的類(lèi)。舉例來(lái)說(shuō),涉及到與文件系統(tǒng)協(xié)同工作的類(lèi)就集合在System.IO 命名空間中。命名空間被組織成一個(gè)層次結(jié)構(gòu)(一棵邏輯樹(shù)) 。 樹(shù)根就是SYSTEM 命名空間。 這個(gè)命名空間包含基本的數(shù)據(jù)類(lèi)型的所有的類(lèi),例如:字符串、數(shù)組,還包含提供隨機(jī)數(shù)字和日期的類(lèi)。你通過(guò)完整的類(lèi)的命名空間能唯一識(shí)別任何的類(lèi)在.NET framework中的位置。 舉例來(lái)說(shuō),指定找到一個(gè)the File class 類(lèi),按如下操:System.IO.文件System.IO指命名空間 ,而文件指定特定的類(lèi)。提示你能夠?yàn)g覽.NET Framework所有的標(biāo)準(zhǔn)類(lèi)的命名空間。通過(guò).NET Framework 的參考文檔可以瀏覽類(lèi)庫(kù)。標(biāo)準(zhǔn)的 ASP.NET 命名空間在默認(rèn)情況下,在你的ASP.NET頁(yè)面中,類(lèi)被包含在一個(gè)選定的命名空間中這些默認(rèn)的命名空間使你在ASP.NET中最常用到的。System 命名空間- 包含所有的基本數(shù)據(jù)類(lèi)型和其他有用的類(lèi),例如:那些關(guān)于產(chǎn)生隨機(jī)數(shù)字和日期的類(lèi)。System.Collections命名空間- 包含的類(lèi)是標(biāo)準(zhǔn)的集合類(lèi),例如:哈希表,數(shù)組列表。System.Collections.Specialized 命名空間- 包含特殊的集合類(lèi),例如:連接列表和字符串集合。 System.Configuration 命名空間- 包括Web.config files類(lèi)。System.Text命名空間-包含編碼,解碼和操作字符串內(nèi)容的類(lèi)。System.Text.RegularExpressions命名空間- 包含的是匹配正則表達(dá)式和替代操作類(lèi)。System.Web 命名空間-工作在萬(wàn)維網(wǎng)方面包含的是瀏覽器請(qǐng)求和服務(wù)器響應(yīng)的類(lèi)。System.Web.Caching 命名空間- 包含頁(yè)面緩沖內(nèi)容和自定義緩沖操作的類(lèi)。System.Web.Security命名空間- 包含執(zhí)行驗(yàn)證和授權(quán),例如:窗體和密碼驗(yàn)證的類(lèi)。System.Web.SessionState命名空間- 包含執(zhí)行保存狀態(tài)的類(lèi)。System.Web.UI命名空間- 包含構(gòu)建 ASP.NET 頁(yè)面的用戶(hù)接口的類(lèi)。 System.Web.UI.HTMLControls命名空間- 包含 HTML 控件的類(lèi)。System.Web.UI.WebControls命名空間- 包含Web控件的類(lèi)。.NET Framework -可用的語(yǔ)言這一本書(shū)的目的, 你將會(huì)為以 Visual Basic 作為你的編程語(yǔ)言來(lái)完成你的 ASP.NET 頁(yè)寫(xiě)程序編寫(xiě)。 它是 ASP.NET 頁(yè)面的默認(rèn)語(yǔ)言。雖然你在這一本書(shū)中一直用 Visual Basic, 但是,你也需要了解用其它的支持公共語(yǔ)言庫(kù)的語(yǔ)言創(chuàng)建ASP.NET頁(yè)面。除此之外,這包括 C#, JScript.NET和C+ 。提示本書(shū)所含的光碟包含 C# 源代碼。除微軟之外的公司產(chǎn)生的幾十個(gè)其他的語(yǔ)言已經(jīng)能夠和.NET framework兼容。 這些其他的語(yǔ)言的一些例子包括 Python、 SmallTalk 、 Eiffel和 COBOL。這就意味著假如你真的想, 你可以使用 COBOL 寫(xiě) ASP.NET 頁(yè)面。不管你使用什么語(yǔ)言開(kāi)發(fā) ASP.NET 頁(yè)面,你需要明白ASP.NET在執(zhí)行前必須編譯,這就意味著ASP.NET執(zhí)行速度非???。你第一次請(qǐng)求 ASP.NET 頁(yè)面, 頁(yè)面被編譯成一個(gè).NET類(lèi), 這個(gè)類(lèi)文件被保存在一個(gè)特殊的目錄下這個(gè)目錄的名字叫Temporary ASP.NET Files。對(duì)于一個(gè)ASP.NET頁(yè)面一個(gè)通信類(lèi)文件出現(xiàn)在Temporary ASP.NET Files目錄下。以后不管任何時(shí)候你請(qǐng)求那個(gè)同樣的ASP.NET頁(yè)面,那個(gè)通信類(lèi)文件就會(huì)執(zhí)行。當(dāng) ASP.NET 頁(yè)面被編譯的時(shí)候,它沒(méi)被直接地被編譯成機(jī)器碼而是被編譯成了一個(gè)中間語(yǔ)言,名字叫 (MSIL)所有.NET可用的語(yǔ)言都被編譯成這種中間語(yǔ)言。一個(gè)ASP.NET 頁(yè)面不會(huì)被編譯成本地機(jī)器碼直到它被一個(gè)瀏覽器訪(fǎng)問(wèn),在那個(gè)時(shí)間點(diǎn)包含在Temporary ASP.NET Files目錄下的類(lèi)文件用JIT編譯器編譯并且執(zhí)行。這些迷惑的方面體現(xiàn)在整個(gè)過(guò)程都在后臺(tái)運(yùn)行,你必須要做的是用資源代碼為你的ASP.NET頁(yè)面創(chuàng)建一個(gè)文本文件。.NET framework 為你處理完轉(zhuǎn)換它為編譯碼這一困難工作。典型ASP提示VBScript 怎么樣呢? 在 ASP.NET 之前, VBScript 是開(kāi)發(fā)動(dòng)態(tài)頁(yè)面最流行的語(yǔ)言。ASP.NET 不支持VBScript ,而且這是好消息。 Visual Basic 是一個(gè) VBScript 的超集,意味著 Visual Basic 相對(duì)于 VBScript有更多的功能。 因此, 你用 Visual Basic 有更豐富的函數(shù)和語(yǔ)句供你使用。此外,不像 VBScript , Visual Basic 是一種被編譯的語(yǔ)言。 這意味著如果你使用 Visual Basic 重寫(xiě)相同的 VBScript代碼感覺(jué)會(huì)更容易一些。假如你過(guò)去只用VBScript而不用 Visual Basic,也不用擔(dān)心。 因?yàn)?VBScript 如此接近 Visual Basic, 你將會(huì)發(fā)現(xiàn)在這二種語(yǔ)言之間的轉(zhuǎn)變是很容易的。提示在.NET framework中,微軟包括一個(gè)名叫 IL Disassembler的有趣的工具。在臨時(shí)的ASP.NET文件目錄中你能使用這個(gè)工具查看沒(méi)有裝配的ASP.NET 類(lèi)的代碼。 它列出了類(lèi)的所有方法和屬性使你能夠?yàn)g覽中間代碼。正如在這章討論的這個(gè)工具也可以用于操作ASP.NET控件。 舉例來(lái)說(shuō),你能使用 IL Disassembler 瀏覽 TextBox 控件的中間代碼。(位于在一個(gè)叫做 System.Web.dll 的文件中)介紹 ASP.NET 控件ASP.NET 控件為你的Web應(yīng)用程序提供動(dòng)態(tài)和交互的用戶(hù)接口。這些控件能夠使你的網(wǎng)站的使用者看見(jiàn)和交互。 舉例來(lái)說(shuō),你能使用控件建立 HTML 窗體元素,交互式日歷, 而且可以滾動(dòng)標(biāo)題廣告。ASP.NET 控件和 HTML 內(nèi)容共存。 典型地,你用通常的 HTML 創(chuàng)建你的網(wǎng)頁(yè)的靜態(tài)區(qū)域和用 ASP.NET 控件創(chuàng)建網(wǎng)頁(yè)的動(dòng)態(tài)區(qū)域。了解 ASP.NET 控件是怎么工作的?最好的方法是看一個(gè)簡(jiǎn)單的Web應(yīng)用窗體頁(yè)面。添加ASP.NET頁(yè)面的代碼第二個(gè)難點(diǎn)就是ASP.NET頁(yè)面的代碼,他是確切的頁(yè)面的程序代碼,在你添加的程序用戶(hù)處理控件也頁(yè)面事件。如果一個(gè)使用者單擊 HTML窗體中的Button按鈕, 舉例來(lái)說(shuō),那個(gè)按鈕就會(huì)響應(yīng)一個(gè)事件 (單擊事件) 。 典型地,你想添加代碼響應(yīng)這個(gè)事件到頁(yè)面中。 舉例來(lái)說(shuō),當(dāng)某人單擊Button按鈕控件的時(shí)候,你可以保存窗體數(shù)據(jù)到一個(gè)文件或者數(shù)據(jù)庫(kù)??丶皇俏ㄒ坏哪芟鄳?yīng)事件的事物。 當(dāng)它被請(qǐng)求的時(shí)候一個(gè)ASP.NET 頁(yè)面每次都能夠響應(yīng)幾個(gè)事件。 舉例來(lái)說(shuō),每當(dāng)你請(qǐng)求一個(gè)頁(yè)面,頁(yè)面的初始化事件就會(huì)被觸發(fā)。 每當(dāng)初始化事件發(fā)生的時(shí)候,你能夠添加代碼到頁(yè)面中來(lái)執(zhí)行。2. 用Web服務(wù)器控件創(chuàng)建窗體構(gòu)建靈活窗體你用幾個(gè)基本W(wǎng)eb控件來(lái)代替標(biāo)準(zhǔn)的 HTML 窗體元素,例如radio buttons、text boxes, and list boxes. 你能夠用這些控件為你的Web應(yīng)用程序在你的ASP.NET頁(yè)面中創(chuàng)建用戶(hù)界面。 下面的部分為這些Web控件提供了詳細(xì)的提綱和程序源代碼。控制頁(yè)面瀏覽在下列的部分中,你學(xué)會(huì)如何控制一個(gè)用戶(hù)從一個(gè)ASP.NET頁(yè)面轉(zhuǎn)到另一個(gè)頁(yè)面。首先,你學(xué)會(huì)怎么把一個(gè)HTML窗體鏈接到另一個(gè)頁(yè)面來(lái)獲取信息。 下一步,你學(xué)會(huì)用Redirect()方法自動(dòng)讓一個(gè)用戶(hù)瀏覽一個(gè)新的頁(yè)面。 最后,你學(xué)會(huì)用超級(jí)鏈接控件怎么把頁(yè)面連在一起。對(duì)控件應(yīng)用格式在下列的部分中,你學(xué)會(huì)該如何創(chuàng)建更有吸引力的Web窗體。 首先,你瀏覽一下針對(duì)所有Web控件格式屬性他們是基本控件類(lèi)的格式屬性。 然后,你學(xué)會(huì)在Web控件上應(yīng)用樣式表風(fēng)格。3. 用驗(yàn)證控件做頁(yè)面驗(yàn)證使用客戶(hù)端驗(yàn)證傳統(tǒng)地,當(dāng)增加驗(yàn)證到他們的頁(yè)面中時(shí),他們會(huì)面臨一個(gè)嚴(yán)峻的選擇。 你可以添加窗體頁(yè)面驗(yàn)證規(guī)則到你的服務(wù)器端代碼,或者是添加驗(yàn)證規(guī)則到你的客戶(hù)端代碼。寫(xiě)驗(yàn)證代碼到客戶(hù)端代碼中的優(yōu)勢(shì)能夠及時(shí)反饋到你的用戶(hù)。 舉例來(lái)說(shuō),一個(gè)使用者忽略在一個(gè)要求檢驗(yàn)的字段中輸入一個(gè)值,你能夠及時(shí)的顯示一個(gè)錯(cuò)誤信息而不需要返回到服務(wù)器端解決。人們喜歡客戶(hù)端的驗(yàn)證。 它看起來(lái)很棒而且產(chǎn)生一種比較好的效果。 然而,問(wèn)題是它不與所有的瀏覽器兼容。 不是所有的瀏覽器支持 JavaScript、不同版本的瀏覽器的不同版本支持 JavaScript,所以客戶(hù)端驗(yàn)證沒(méi)有保障。由于這個(gè)原因,許多開(kāi)發(fā)者在過(guò)去決定添加自定義驗(yàn)證到服務(wù)器端。因?yàn)榉?wù)器端代碼能夠和任何瀏覽器協(xié)同工作。就這樣的做法更有安全的保障。幸運(yùn)地,正如在章節(jié)討論的這些驗(yàn)證控件不會(huì)強(qiáng)迫你做困難的選擇。 這些驗(yàn)證控件會(huì)自動(dòng)地產(chǎn)生客戶(hù)端代碼和服務(wù)器端代碼。 如果一個(gè)瀏覽器有能力支持JavaScript ,客戶(hù)端的驗(yàn)證腳本將會(huì)自動(dòng)返回到瀏覽器。 如果一個(gè)瀏覽器不支持 JavaScript,那個(gè)驗(yàn)證規(guī)則會(huì)自動(dòng)在服務(wù)器端代碼中執(zhí)行。然而你需要注意的是,客戶(hù)端的驗(yàn)證僅僅能夠工作在IE4.0或更高的版本。 尤其,正如這一章討論的客戶(hù)端腳本不可能在任意本本的瀏覽器中運(yùn)行。控制字段: RequiredFieldValidator 控件你用這個(gè)控件來(lái)檢查在一個(gè)Web窗體中是否為空, 典型地,你和 TextBox 控件一起使用這個(gè)控件。 然而,這個(gè)控件也可以用在其他的輸入型控件,例如:RadioButtonList.控件。驗(yàn)證表達(dá)式: RegularExpressionValidator 控件你能使用 RegularExpressionValidator 控件來(lái)驗(yàn)證輸入的值是否和定義的正則表達(dá)式相匹配。 例如:你能使用這控件來(lái)檢查一個(gè)用戶(hù)是否輸入一個(gè)合法的電子郵件地址,電話(huà)號(hào)碼,用戶(hù)名或密碼。怎樣用一個(gè)正則表達(dá)式來(lái)完成這些驗(yàn)證任務(wù)將會(huì)在下面的例子中一一列出。 比較值: CompareValidator 控件這個(gè)CompareValidator 控件用于比較一個(gè)輸入的數(shù)據(jù)和另外一個(gè)值是否相同。另外一個(gè)值可能是固定值,例如:一個(gè)特定的數(shù)字或者是輸入到另一個(gè)控件中的一個(gè)值??偨Y(jié)錯(cuò)誤: ValidationSummary 控件假想一個(gè)頁(yè)面有50個(gè)字段假如你僅僅用上部分討論的那些驗(yàn)證控件來(lái)顯示錯(cuò)誤看見(jiàn)一個(gè)錯(cuò)誤在頁(yè)面中將是很難的。 例如:你可能需要滾動(dòng)到第48個(gè)頁(yè)面字段來(lái)找到這個(gè)錯(cuò)誤信息。幸好,微軟除了包含上面提到的控件還包括 ValidationSummary 控件。 你能用這控件綜合所有的錯(cuò)誤信息在一個(gè)頁(yè)面的上端或者你想要的任何一個(gè)地方。4. 先進(jìn)的控件編程保存瀏覽狀態(tài)默認(rèn)地,幾乎所有的 ASP.NET 控件都會(huì)在先前的窗體中保留他們的屬性值。 舉例來(lái)說(shuō),如果你輸入文本到一個(gè)Lebel標(biāo)簽上然后提交那個(gè)頁(yè)面,當(dāng)那個(gè)頁(yè)面再次被訪(fǎng)問(wèn)那個(gè)Lebel標(biāo)簽的內(nèi)容將會(huì)被保存下來(lái)。瀏覽狀態(tài)的妙處是它不依賴(lài)任何的特定服務(wù)器或?yàn)g覽器的屬性。 尤其,它不依賴(lài)cookies, session變量、或應(yīng)用程序變量。 瀏覽狀態(tài)在一個(gè)名叫做VIEWSTATE的隱藏頁(yè)面中執(zhí)行,這個(gè)隱藏頁(yè)面自動(dòng)創(chuàng)建每個(gè)Web窗體。當(dāng)靈活的應(yīng)用時(shí), 瀏覽狀態(tài)能夠在你的網(wǎng)站中產(chǎn)生藝術(shù)性的和積極的效果,例如:如果你在一個(gè)支持瀏覽狀態(tài)的控件中顯示數(shù)據(jù)庫(kù)數(shù)據(jù),你不需要每次都返回到需要反饋到服務(wù)器的數(shù)據(jù)庫(kù)頁(yè)面。 你能夠自動(dòng)地保存頁(yè)面里的數(shù)據(jù)狀態(tài)。顯示和隱藏內(nèi)容假想你正在用一個(gè)可選擇的部分創(chuàng)造頁(yè)面。 舉例來(lái)說(shuō),假想你正在創(chuàng)造一種在線(xiàn)納稅系統(tǒng),而且你想要顯示或者隱藏一個(gè)包含適用于已婚的稅文件編檔員的問(wèn)題的部分?;蛘? 假想你想要添加一個(gè)幫助按鈕到網(wǎng)站上去。 你可能想要隱藏或者顯示完成依靠用戶(hù)參考的問(wèn)題的詳細(xì)說(shuō)明。最后,假想你想要把一個(gè)tax form 變成很多頁(yè)面,以便一個(gè)人每次只看那個(gè)tax form的一部分。在下列的部分中,你學(xué)會(huì)用屬性設(shè)置在一個(gè)窗體中來(lái)隱藏或顯示控件。 你學(xué)會(huì)用單個(gè)控件和一組控件設(shè)置Visible and Enabled屬性來(lái)隱藏和顯示頁(yè)面內(nèi)容。使用Visible and Enabled屬性每個(gè)控件,包括 HTML 和Web控件,有一個(gè)Visible 屬性來(lái)決定那個(gè)控件是否可見(jiàn)。 當(dāng)一個(gè)控件的Visible是false值,那個(gè)控件就不會(huì)在頁(yè)面上顯示;那個(gè)控件也不會(huì)進(jìn)一步運(yùn)行。Web控件 (不是每個(gè)HTML 控件) 還有一個(gè)叫Enabled的屬性。當(dāng)Enabled的屬性是false值,你用的瀏覽器是IE4.0或更高的版本那個(gè)控件被封住了,也不起作用了,當(dāng)用其他的瀏覽器的時(shí)候,如:網(wǎng)景瀏覽器那個(gè)控件不會(huì)被封,但它也是不起作用的。使瀏覽狀態(tài)失效在特定的環(huán)境中,你可能想要對(duì)一個(gè)單獨(dú)的控件或ASP.NET頁(yè)面作為一個(gè)整體的瀏覽狀態(tài)失效。 舉例來(lái)說(shuō), 你可能使用一個(gè)有包含許多數(shù)據(jù)的控件.(假想一個(gè)RadioButtonList 控件控制1,000 個(gè)選項(xiàng))假如你擔(dān)心頁(yè)面數(shù)據(jù)會(huì)大大的降低頁(yè)面的顯示速度,你可能不想要加載數(shù)據(jù)到隱藏的VIEWSTATE頁(yè)面字段。使用豐富頁(yè)面的控件在下列的部分中,你學(xué)會(huì)在ASP.NET Framework怎樣使用三種特征控件。學(xué)會(huì)該如何使用日歷控件顯示交互式日歷,AdRotator控件顯示滾動(dòng)的廣告,HTMLInputFile控件來(lái)接受文件的上傳。 麥克唐納、茲普茲塔著ASP.NET 3.5高級(jí)程序設(shè)計(jì)(第2版)ASP.NET Technique1. Building ASP.NET PagesASP.NET and the .NET FrameworkASP.NET is part of Microsofts overall .NET framework, which contains a vast set of programming classes designed to satisfy any conceivable programming need. In the following two sections, you learn how ASP.NET fits within the .NET framework, and you learn about the languages you can use in your ASP.NET pages.The .NET Framework Class LibraryImagine that you are Microsoft. Imagine that you have to support multiple programming languagessuch as Visual Basic, JScript, and C+. A great deal of the functionality of these programming languages overlaps. For example, for each language, you would have to include methods for accessing the file system, working with databases, and manipulating strings.Furthermore, these languages contain similar programming constructs. Every language, for example, can represent loops and conditionals. Even though the syntax of a conditional written in Visual Basic differs from the syntax of a conditional written in C+, the programming function is the same.Finally, most programming languages have similar variable data types. In most languages, you have some means of representing strings and integers, for example. The maximum and minimum size of an integer might depend on the language, but the basic data type is the same.Maintaining all this functionality for multiple languages requires a lot of work. Why keep reinventing the wheel? Wouldnt it be easier to create all this functionality once and use it for every language?The .NET Framework Class Library does exactly that. It consists of a vast set of classes designed to satisfy any conceivable programming need. For example, the .NET framework contains classes for handling database access, working with the file system, manipulating text, and generating graphics. In addition, it contains more specialized classes for performing tasks such as working with regular expressions and handling network protocols.The .NET framework, furthermore, contains classes that represent all the basic variable data types such as strings, integers, bytes, characters, and arrays.Most importantly, for purposes of this book, the .NET Framework Class Library contains classes for building ASP.NET pages. You need to understand, however, that you can access any of the .NET framework classes when you are building your ASP.NET pages.Understanding NamespacesAs you might guess, the .NET framework is huge. It contains thousands of classes (over 3,400). Fortunately, the classes are not simply jumbled together. The classes of the .NET framework are organized into a hierarchy of namespaces.ASP Classic NoteIn previous versions of Active Server Pages, you had access to only five standard classes (the Response, Request, Session, Application, and Server objects). ASP.NET, in contrast, provides you with access to over 3,400 classes!A namespace is a logical grouping of classes. For example, all the classes that relate to working with the file system are gathered together into the System.IO namespace.The namespaces are organized into a hierarchy (a logical tree). At the root of the tree is the System namespace. This namespace contains all the classes for the base data types, such as strings and arrays. It also contains classes for working with random numbers and dates and times.You can uniquely identify any class in the .NET framework by using the full namespace of the class. For example, to uniquely refer to the class that represents a file system file (the File class), you would use the following:System.IO.FileSystem.IO refers to the namespace, and File refers to the particular class.NOTEYou can view all the namespaces of the standard classes in the .NET Framework Class Library by viewing the Reference Documentation for the .NET Framework.Standard ASP.NET NamespacesThe classes contained in a select number of namespaces are available in your ASP.NET pages by default. (You must explicitly import other namespaces.) These default namespaces contain classes that you use most often in your ASP.NET applications:System Contains all the base data types and other useful classes such as those related to generating random numbers and working with dates and times.System.Collections Contains classes for working with standard collection types such as hash tables, and array lists.System.Collections.Specialized Contains classes that represent specialized collections such as linked lists and string collections.System.Configuration Contains classes for working with configuration files (Web.config files).System.Text Contains classes for encoding, decoding, and manipulating the contents of strings.System.Text.RegularExpressions Contains classes for performing regular expression match and replace operations.System.Web Contains the basic classes for working with the World Wide Web, including classes for representing browser requests and server responses.System.Web.Caching Contains classes used for caching the content of pages and classes for performing custom caching operations.System.Web.Security Contains classes for implementing authentication and authorization such as Forms and Passport authentication.System.Web.SessionState Contains classes for implementing session state.System.Web.UI Contains the basic classes used in building the user interface of ASP.NET pages.System.Web.UI.HTMLControls Contains the classes for the HTML controls.System.Web.UI.WebControls Contains the classes for the Web controls.NET Framework-Compatible LanguagesFor purposes of this book, you will write the application logic for your ASP.NET pages using Visual Basic as your programming language. It is the default language for ASP.NET pages. Although you stick to Visual Basic in this book, you also need to understand that you can create ASP.NET pages by using any language that supports the .NET Common Language Runtime. Out of the box, this includes C#, JScript.NET, and the Managed Extensions to C+.NOTEThe CD included with this book contains C# versions of all the code samples.Dozens of other languages created by companies other than Microsoft have been developed to work with the .NET framework. Some examples of these other languages include Python, SmallTalk, Eiffel, and COBOL. This means that you could, if you really wanted to, write ASP.NET pages using COBOL.Regardless of the language that you use to develop your ASP.NET pages, you need to understand that ASP.NET pages are compiled before they are executed. This means that ASP.NET pages can execute very quickly.The first time you request an ASP.NET page, the page is compiled into a .NET class, and the resulting class file is saved beneath a special directory on your server named Temporary ASP.NET Files. For each and every ASP.NET page, a corresponding class file appears in the Temporary ASP.NET Files directory. Whenever you request the same ASP.NET page in the future, the corresponding class file is executed.When an ASP.NET page is compiled, it is not compiled directly into machine code. Instead, it is compiled into an intermediate-level language called Microsoft Intermediate Language (MSIL). All .NET-compatible languages are compiled into this intermediate language.An ASP.NET page isnt compiled into native machine code until it is actually requested by a browser. At that point, the class file contained in the Temporary ASP.NET Files directory is compiled with the .NET framework Just in Time (JIT) compiler and executed.The magical aspect of this whole process is that it happens automatically in the background. All you have to do is create a text file with the source code for your ASP.NET page, and the .NET framework handles all the hard work of converting it into compiled code for you.ASP CLASSIC NOTEWhat about VBScript? Before ASP.NET, VBScript was the most popular language for developing Active Server Pages.ASP.NET does not support VBScript, and this is good news. Visual Basic is a superset of VBScript, which means that Visual Basic has all the functionality of VBScript and more. So, you have a richer set of functions and statements with Visual Basic.Furthermore, unlike VBScript, Visual Basic is a compiled language. This means that if you use Visual Basic to rewrite the same code that you wrote with VBScript, you can get better performance.If you have worked only with VBScript and not Visual Basic in the past, dont worry. Since VBScript is so closely related to Visual Basic, youll find it easy to make the transition between the two languages.NOTEMicrosoft includes an interesting tool named the IL Disassembler (ILDASM) with the .NET framework. You can use this tool to view the disassembled code for any of the ASP.NET classes in the Temporary ASP.NET Files directory. It lists all the methods and properties of the class and enables you to view the intermediate-level code.This tool also works with all the ASP.NET controls discussed in this chapter. For example, you can use the IL Disassembler to view the intermediate-level code for the TextBox control (located in a file named System.Web.dll).Introducing ASP.NET ControlsASP.NET controls provide the dynamic and interactive portions of the user interface for your Web application. The controls render the content that the users of your Web site actually see and interact with. For example, you can use controls to create HTML form elements, interactive calendars, and rotating banner advertisements.ASP.NET controls coexist peacefully with HTML content. Typically, you create the static areas of your Web pages with normal HTML content and create the dynamic or interactive portions with ASP.NET controls.The best way to understand how ASP.NET controls work in an HTML page is to look at a simple Web Forms Page.Adding Application Logic to an ASP.NET PageThe second building block of an ASP.NET page is the application logic, which is the actual programming code in the page. You add application logic to a page to handle both control and page events.If a user clicks a Button control within an HTML form, for example, the Button control raises an event (the Click event). Typically, you want to add code to the page that does something in response to this event. For example, when someone clicks the Button control, you might want to save the form data to a file or database.Controls are not the only things that can raise events. An ASP.NET page itself raises several events every time it is requested. For example, whenever you request a page, the pages Load event is triggered. You can add application logic to the page that executes whenever the Load event occurs.2. Building Forms with Web Server ControlsBuilding Smart FormsYou use several of the basic Web controls to represent standard HTML form elements such as radio buttons, text boxes, and list boxes. You can use these controls in your ASP.NET pages to create the user interfac
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 網(wǎng)店賬戶(hù)及電商團(tuán)隊(duì)管理交接服務(wù)合同
- 古建筑結(jié)構(gòu)安全監(jiān)測(cè)租賃合同(含現(xiàn)場(chǎng)勘查)
- 電視劇特效化妝假發(fā)租賃及后期制作服務(wù)合同
- 生物制藥核心專(zhuān)利技術(shù)授權(quán)與市場(chǎng)保護(hù)合同
- 互聯(lián)網(wǎng)金融服務(wù)合作與技術(shù)秘密保護(hù)協(xié)議
- 跨國(guó)婚姻忠誠(chéng)協(xié)議與海外財(cái)產(chǎn)轉(zhuǎn)移合同
- 影視特效血液儲(chǔ)存設(shè)備租賃及安全檢測(cè)協(xié)議
- DB42-T 2003-2023 東方百合鮮切花設(shè)施生產(chǎn)技術(shù)規(guī)程
- 汽車(chē)發(fā)動(dòng)機(jī)構(gòu)造與拆裝 課件 金濤 任務(wù)1-10 汽車(chē)發(fā)動(dòng)機(jī)整體機(jī)構(gòu)的認(rèn)識(shí)-水泵的認(rèn)識(shí)與拆裝
- 2023年人教版四年級(jí)語(yǔ)文上冊(cè)八單元測(cè)試卷及答案
- 2023年11月2024中咨公司校園公開(kāi)招聘筆試歷年高頻考點(diǎn)-難、易錯(cuò)點(diǎn)薈萃附答案帶詳解
- 人工智能在教育中的語(yǔ)文教學(xué)應(yīng)用
- 消防救援-水域救援-冰域救援技術(shù)課件
- 30萬(wàn)級(jí)潔凈車(chē)間溫濕度標(biāo)準(zhǔn)
- 質(zhì)量風(fēng)險(xiǎn)與機(jī)遇分析評(píng)價(jià)表完整
- 放射免疫技術(shù)(免疫學(xué)檢驗(yàn)課件)
- 濱江文化片區(qū)概念規(guī)劃
- 爛尾樓分析完整版
- 大思政研究論文:大中小學(xué)思政課一體化的內(nèi)容要求與推進(jìn)措施
- 二輪復(fù)習(xí)《健康的生活》教案
- GB/T 15812-1995醫(yī)用高分子軟管物理性能試驗(yàn)方法
評(píng)論
0/150
提交評(píng)論