(第1課)ASP.NET網站開發——ASP.NET4.0概述
阿新 • • 發佈:2019-02-18
靜態網頁(HTML)
在記事本中寫入如下程式碼,然後把檔名副檔名改成.html,雙擊執行即可看到瀏覽器頁面如下顯示。
動態網頁(HTML表單)
ASP.NET Web窗體
下面摘選自《Web程式設計——ASP.NET網站開發》 陳作聰 王永皎 程鳳娟 編著
在ASP.NET中,傳送到客戶端瀏覽器中的網頁是經過.NET框架中的基類動態生成的。這個基類就是Web頁面框架中的Page類,而例項化的Page類就是一個Web窗體,也就是Web Forms。因此,一個ASP.NET頁面就是一個Web窗體。而作為窗體物件,就具有屬性、方法和事件,可以作為容器容納其他控制元件。
後臺隱藏內碼表
下面摘選自《Web程式設計——ASP.NET網站開發》 陳作聰 王永皎 程鳳娟 編著
後臺隱藏內碼表與早期指令碼語言的將程式碼和HTML標記混合在一起編寫不同。它是將業務邏輯的處理程式碼都存放在.cs檔案中,當ASP.NET網頁執行時,ASP.NET類生成時會先處理.cs檔案中的程式碼,再處理.aspx頁面中的程式碼,這種過程成為程式碼分離。優點:美工人員設計.aspx頁面,而.cs檔案由程式設計人員來完成業務邏輯的處理。
ASP.NET開發環境搭建
- 安裝配置IIS Web伺服器
- 安裝Visual Studio
具體步驟略。
第一個ASP.NET網頁
C#入門
下面主要參考《Web程式設計——ASP.NET網站開發》 陳作聰 王永皎 程鳳娟 編著
【例1—C#面向過程】統計使用者輸入的字串中每個字母(不區分大小寫)和其他字元出現的次數
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string [] args)
{
int[] charNum = new int[26];
int other=0;
string str;
Console.Write("請輸入字串:");
str = Console.ReadLine();
str = str.ToUpper();
for(int i = 0; i < str.Length; i++)
{
char tmp = str[i];
if(tmp>='A' && tmp <= 'Z')
{
charNum[tmp - 'A']++;
}
else
{
other++;
}
}
Console.WriteLine("字元 出現次數");
for(int i = 0; i < 26; i++)
{
Console.WriteLine("{0} {1}", (char)(i + 'A'), charNum[i]);
}
Console.WriteLine("other {0}",other);
}
}
}
【例2—C#面向物件】
月利息=授信額度*年利率/12
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
class Account
{
protected decimal money;
public Account()
{
money = 10000;
}
}
class CreditAccount : Account
{
private static double interestRate = 0.0234;
public CreditAccount() { }
public void Total(decimal number)
{
if (number > money)
{
Console.WriteLine("超過授信額度!");
}
else
{
Console.WriteLine("月息是:" + number * Convert.ToDecimal(interestRate) / 12);
}
}
public void Change(decimal m)
{
money = m;
Console.WriteLine("授信額度調整為:" + money);
}
}
static void Main(string[] args)
{
CreditAccount ca = new CreditAccount();
ca.Total(8000);
ca.Total(15000);
ca.Change(40000);
ca.Total(40000);
}
}
}