顯示具有 [電腦][程式設計][ASP.NET]C# 標籤的文章。 顯示所有文章
顯示具有 [電腦][程式設計][ASP.NET]C# 標籤的文章。 顯示所有文章

2012年11月1日 星期四

C#.NET 程式碼中對多個控制項指定單一事件處理程序

在 aspx 檔案中,不直接針對「控制項」指定「事件處理程序」,而是在 aspx.cs 檔案中透過程式碼去指定。

我們在介面中設計三個按鈕,其 ID 及 Text 屬性為 Button1~Button3 ,並且提供了三個 Label 供我們顯示測試的輸出結果。

<test.aspx>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button1" />
        <asp:Button ID="Button2" runat="server" Text="Button2" />
        <asp:Button ID="Button3" runat="server" Text="Button3" />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <br />
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>