Button 클래스
업데이트: 2007년 11월
웹 페이지에 누름 단추 컨트롤을 표시합니다.
어셈블리: System.Web(System.Web.dll)
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class Button : WebControl, IButtonControl, IPostBackEventHandler
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */ /** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */ public class Button extends WebControl implements IButtonControl, IPostBackEventHandler
public class Button extends WebControl implements IButtonControl, IPostBackEventHandler
<asp:Button />
Button 컨트롤을 사용하여 웹 페이지에 누름 단추를 만듭니다. 전송 단추 또는 명령 단추를 만들 수 있습니다.
기본적으로 Button 컨트롤은 전송 단추입니다. 전송 단추에는 연결된 명령 이름(CommandName 속성에서 지정)이 없으며 단지 웹 페이지를 서버로 포스트백합니다. Click 이벤트에 대한 이벤트 처리기를 제공하여 전송 단추를 클릭했을 때 수행되는 작업을 프로그래밍 방식으로 제어할 수 있습니다.
명령 단추에는 단추와 연결된 Sort 같은 명령 이름이 있으며 이러한 이름은 CommandName 속성을 통해 설정할 수 있습니다. 이렇게 하면 웹 페이지에서 여러 개의 Button 컨트롤을 만들고 어떤 Button 컨트롤이 클릭되는지 프로그래밍 방식으로 확인할 수 있습니다. 또한 명령 단추에 CommandArgument 속성을 사용하면 수행할 명령에 대한 추가 정보(예: Ascending)를 제공할 수 있습니다. Command 이벤트에 대한 이벤트 처리기를 제공하여 명령 단추를 클릭했을 때 수행되는 작업을 프로그래밍 방식으로 제어할 수 있습니다.
기본적으로 Button 컨트롤을 클릭하면 페이지 유효성 검사가 수행됩니다. 페이지 유효성 검사를 수행하면 페이지의 유효성 검사 컨트롤과 관련된 입력 컨트롤이 유효성 검사 컨트롤에서 지정한 유효성 검사 규칙을 모두 통과했는지 여부가 확인됩니다. 유효성 검사를 수행하지 않으려면 CausesValidation 속성을 false로 설정합니다.
액세스 가능성
이 컨트롤에 대해 기본적으로 렌더링되는 태그는 WCAG(Web Content Accessibility Guidelines) 1.0 우선 순위 1 지침과 같은 내게 필요한 옵션 표준을 따르지 않을 수도 있습니다. 이 컨트롤의 내게 필요한 옵션 지원에 대한 자세한 내용은 ASP.NET 컨트롤 및 내게 필요한 옵션을 참조하십시오.
| Topic | Location |
|---|---|
| 방법: DataList, Repeater 또는 GridView 항목에서 단추 이벤트에 대한 응답 | Building ASP .NET Web Applications |
| 연습: ASP.NET 웹 서버 컨트롤의 기본 컨트롤 디자이너 만들기 | Authoring ASP.NET Controls |
| 연습: Visual Web Developer에서 CSS 스타일시트 작업 | Building ASP .NET Web Applications in Visual Studio |
| 연습: ASP.NET 사용자 정의 컨트롤을 사용하여 재사용 가능한 요소 만들기 | Building ASP .NET Web Applications in Visual Studio |
| 연습: Web Forms 페이지에서 사용자 입력 유효성 검사 | Building ASP .NET Web Applications in Visual Studio |
| 방법: ASP.NET 웹 페이지에서 이벤트 처리기 만들기(Visual Studio) | Building ASP .NET Web Applications in Visual Studio |
| 연습: 사용자 지정 비즈니스 개체에 데이터 바인딩 | Building ASP .NET Web Applications in Visual Studio |
| 방법: Web Forms 페이지에 Button 웹 서버 컨트롤 추가(Visual Studio) | Building ASP .NET Web Applications in Visual Studio |
| 방법: Web Forms 페이지에 Button 웹 서버 컨트롤 추가 | Building ASP .NET Web Applications |
| 방법: ASP.NET 웹 서버 컨트롤에 포커스 설정 | Building ASP .NET Web Applications |
| 방법: 데이터 바인딩 컨트롤의 단추 이벤트에 응답 | Building ASP .NET Web Applications |
| 방법: Button 웹 서버 컨트롤 이벤트에 응답 | Building ASP .NET Web Applications |
| 연습: Visual Web Developer에서 ASP.NET 마스터 페이지 생성 및 사용 | Building ASP .NET Web Applications in Visual Studio |
| 연습: Visual Web Developer에서 기본 웹 페이지 만들기 | Building ASP .NET Web Applications in Visual Studio |
| 연습: Visual Studio에서 테마를 사용하여 웹 사이트 사용자 지정 | Building ASP .NET Web Applications in Visual Studio |
| 방법: 클라이언트 스크립트에서 단추 웹 서버 컨트롤 이벤트에 응답 | Building ASP .NET Web Applications |
| 방법: ASP.NET 웹 페이지에서 단일 이벤트 처리기에 여러 이벤트 연결 | Building ASP .NET Web Applications |
| 방법: 이벤트를 발생시킨 웹 서버 컨트롤 확인 | Building ASP .NET Web Applications |
| 방법: Web Forms 페이지에 PlaceHolder 웹 서버 컨트롤 추가 | Building ASP .NET Web Applications |
| 연습: 웹 서버 컨트롤의 기본 컨트롤 디자이너 만들기 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 방법: 클라이언트 스크립트에서 단추 웹 서버 컨트롤 이벤트에 응답 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 방법: ASP.NET 웹 페이지에서 단일 이벤트 처리기에 여러 이벤트 연결 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 방법: 이벤트를 발생시킨 웹 서버 컨트롤 확인 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 연습: ASP.NET 사용자 정의 컨트롤을 사용하여 재사용 가능한 요소 만들기 | Visual Web Developer를 사용하여 응용 프로그램 빌드 |
| 연습: Visual Web Developer에서 ASP.NET 마스터 페이지 생성 및 사용 | Visual Web Developer를 사용하여 응용 프로그램 빌드 |
| 연습: Web Forms 페이지에서 사용자 입력 유효성 검사 | Visual Web Developer를 사용하여 응용 프로그램 빌드 |
| 방법: ASP.NET 웹 서버 컨트롤에 포커스 설정 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 방법: ASP.NET 웹 페이지에서 이벤트 처리기 만들기(Visual Studio) | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 연습: 사용자 지정 비즈니스 개체에 데이터 바인딩 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 연습: Visual Web Developer에서 기본 웹 페이지 만들기 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 방법: Web Forms 페이지에 Button 웹 서버 컨트롤 추가(Visual Studio) | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 방법: Button 웹 서버 컨트롤 이벤트에 응답 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 연습: Visual Studio에서 테마를 사용하여 웹 사이트 사용자 지정 | Visual Web Developer를 사용하여 응용 프로그램 빌드 |
| 방법: 데이터 바인딩 컨트롤의 단추 이벤트에 응답 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
| 방법: DataList 또는 Repeater 항목에서 단추 이벤트에 대한 응답 | Visual Studio에서 ASP .NET 웹 응용 프로그램 빌드 |
다음 예제에서는 웹 페이지 내용을 서버로 포스트백하는 전송 Button 컨트롤을 만드는 방법을 보여 줍니다.
<%@ Page Language="C#" AutoEventWireup="True" %> <!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> <title>Button Example</title> <script language="C#" runat="server"> void SubmitBtn_Click(Object sender, EventArgs e) { Message.Text="Hello World!!"; } </script> </head> <body> <form id="form1" runat="server"> <h3>Button Example</h3> Click on the submit button.<br /><br /> <asp:Button id="Button1" Text="Submit" OnClick="SubmitBtn_Click" runat="server"/> <br /> <asp:label id="Message" runat="server"/> </form> </body> </html>
다음 예제에서는 목록을 정렬하는 명령 Button 컨트롤을 만드는 방법을 보여 줍니다.
<%@ Page Language="C#" AutoEventWireup="True" %> <!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>Button CommandName Example</title> <script runat="server"> void CommandBtn_Click(Object sender, CommandEventArgs e) { switch(e.CommandName) { case "Sort": // Call the method to sort the list. Sort_List((String)e.CommandArgument); break; case "Submit": // Display a message for the Submit button being clicked. Message.Text = "You clicked the Submit button"; // Test whether the command argument is an empty string (""). if((String)e.CommandArgument == "") { // End the message. Message.Text += "."; } else { // Display an error message for the command argument. Message.Text += ", however the command argument is not recogized."; } break; default: // The command name is not recognized. Display an error message. Message.Text = "Command name not recogized."; break; } } void Sort_List(string commandArgument) { switch(commandArgument) { case "Ascending": // Insert code to sort the list in ascending order here. Message.Text = "You clicked the Sort Ascending button."; break; case "Descending": // Insert code to sort the list in descending order here. Message.Text = "You clicked the Sort Descending button."; break; default: // The command argument is not recognized. Display an error message. Message.Text = "Command argument not recogized."; break; } } </script> </head> <body> <form id="form1" runat="server"> <h3>Button CommandName Example</h3> Click on one of the command buttons. <br /><br /> <asp:Button id="Button1" Text="Sort Ascending" CommandName="Sort" CommandArgument="Ascending" OnCommand="CommandBtn_Click" runat="server"/> <asp:Button id="Button2" Text="Sort Descending" CommandName="Sort" CommandArgument="Descending" OnCommand="CommandBtn_Click" runat="server"/> <br /><br /> <asp:Button id="Button3" Text="Submit" CommandName="Submit" OnCommand="CommandBtn_Click" runat="server"/> <asp:Button id="Button4" Text="Unknown Command Name" CommandName="UnknownName" CommandArgument="UnknownArgument" OnCommand="CommandBtn_Click" runat="server"/> <asp:Button id="Button5" Text="Submit Unknown Command Argument" CommandName="Submit" CommandArgument="UnknownArgument" OnCommand="CommandBtn_Click" runat="server"/> <br /><br /> <asp:Label id="Message" runat="server"/> </form> </body> </html>
- AspNetHostingPermission
호스팅된 환경에서 작업하는 데 필요한 권한입니다. 요청 값: LinkDemand; 권한 값: Minimal
- AspNetHostingPermission
호스팅된 환경에서 작업하는 데 필요한 권한입니다. 요청 값: InheritanceDemand; 권한 값: Minimal
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.Button
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.