# 2019/0211/ASP.NET\_Webforms&物件命名空間

語法訓練 / 邏輯訓練 / 整合運用

了解需求 ， 需求轉為邏輯 ，邏輯轉為程式

1-5.寫一顯示1\~100整數中，不是5的倍數的程式。(需求)

如果是5的倍數絕對能被5整除餘數為0。(邏輯)

1.列出1\~100的數字。(邏輯)

for(int i=1;i<=100;i++)  (程式)

2.如果餘數不等於0列出來。(邏輯)

{if(i%5!=0) (程式)

Response.Write(i+" ")}; (程式)

3.得到運算出餘數為零的程式。(程式)

## &#x20;[GUI 应用程序架构](https://segmentfault.com/a/1190000009346599)模式

webform 疊疊樂  利用工具箱 小型系統 開發快速 但大型系統就會超級慢&#x20;

mvc 齒輪 一個卡一個

{% embed url="<https://segmentfault.com/a/1190000009346599>" %}

{% embed url="<https://www.google.com/search?rlz=1C1GCEU_zh-TWTW835&ei=GiJhXMSBNcr28gWAxpiYAQ&q=winforms+mvc+mvp+mvvm&oq=mvc+mvp+mvvm+webfrom&gs_l=psy-ab.1.0.0i8i13i30.7762.12335..14328...0.0..0.84.458.8......0....1..gws-wiz.......0i71j0j0i30j0i8i30j33i160.FAv8l5hzVV0>" %}

## Webforms

Controls 控制項 WinForm

在html上面一定有 asp開頭 且 runat="server" 執行時一定要在伺服器端

控制項一定是物件 ， 但物件不一定是控制項

ID = "???" 識別值 同一個網頁不可重複

### 屬性視窗可查看屬性且可以直接修改

但沒有顯示全部屬性只顯示常用屬性

開啟網頁時執行Page\_load事件內程式碼 &#x20;

點擊按鈕時執行OnClick事件內程式碼&#x20;

在html aspx檔案內

```
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="13WebForm_StandardControls.aspx.cs" Inherits="ASPnet._13WebForm_StandardControls" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <asp:Button ID="Button1" BackColor="#ff0066" ForeColor="White" runat="server" Text="按鈕" OnClick="Button1_Click"  />

            <asp:Button ID="Button2" runat="server" Text="12345" BackColor="#6BE9D6" OnClick="Button2_Click" />
        </div>
    </form>
</body>
</html>
```

在aspx.cs檔案內

```
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Text = "哎呀!!我被按下去了!";
        Button1.Font.Size = FontUnit.Point(36);
        Button2.Text = "哎呀!!Button1被按下去了!";
    }
```

Webfroms 有一堆別人寫好的物件與屬性可以更改所以較少邏輯概念但可以很快製作

右值丟到左值&#x20;

```
Button1.Text = "哎呀!!我被按下去了!";
```

C#裡面&#x20;

\= 指令運算值的左右兩側必須要是相同的型態

左值是字串 右邊也必須是字串

```
Button1.Font.Size = FontUnit.Point(36);
```

在HTML不需要 FontUnit 可以直接給 36

```
<asp:    Button ID="Button2" runat="server" Text="12345" BackColor="#6BE9D6" OnClick="Button2_Click" />
```

### 命名空間

物件的屬性 (變數) = 給予值  (左右物件資料型態很複雜但必須一樣)

( System.Drawing) .  Color

(namespace 命名空間)  類別名稱

![](/files/-LYQeaF76iYIxyKZEEW2)

類別庫裡面有人做了兩個以上相同物件名稱都叫做 Color

請把C502.班長.的 Color 給我用

### .cs檔案的抬頭已經預設一些常用命名空間，所以造成有些程式碼不需要命名空間

![](/files/-LYQdpgNPIcfiR4obk0K)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://johch3n611u.gitbook.io/c50108/ju-li-cheng-bei/201902/20190211-liao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
