System.Web.UI.WebControls 名 ...


.NET Framework クラス ライブラリ
Button クラス

更新 : 2007 年 11 月

Web ページにプッシュ ボタン コントロールを表示します。

名前空間 :  System.Web.UI.WebControls
アセンブリ :  System.Web (System.Web.dll 内)

構文

Visual Basic (宣言)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Button _
    Inherits WebControl _
    Implements IButtonControl, IPostBackEventHandler
Visual Basic (使用法)
Dim instance As Button
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Button : WebControl, IButtonControl, 
    IPostBackEventHandler
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Button : public WebControl, 
    IButtonControl, IPostBackEventHandler
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class Button extends WebControl implements IButtonControl, 
    IPostBackEventHandler
JScript
public class Button extends WebControl implements IButtonControl, IPostBackEventHandler
ASP.NET
<asp:Button />
解説

Button コントロールを使用して、Web ページにプッシュ ボタンを作成します。送信ボタンまたはコマンド ボタンを作成できます。

既定では、Button コントロールは送信ボタンです。送信ボタンに関連付けられているコマンド名 (CommandName プロパティで指定) はありません。このボタンは Web ページをサーバーにポストバックするだけです。Click イベントのイベント ハンドラを作成して、送信ボタンがクリックされたときに実行されるアクションをプログラムにより制御できます。

コマンド ボタンの場合は、CommandName プロパティを設定することにより、Sort などのコマンド名を関連付けることができます。コマンド名を設定すると、Web ページに複数の Button コントロールを作成し、どの Button コントロールがクリックされたかをプログラムによって確認できます。コマンド ボタンの場合は、CommandArgument プロパティを使用して、実行するコマンドに関して昇順などの追加情報も指定できます。Command イベントのイベント ハンドラを作成して、コマンド ボタンがクリックされたときに実行されるアクションをプログラムによって制御できます。

既定では、Button コントロールがクリックされたときにページ検証を実行します。ページ検証は、ページ上にある検証コントロールに関連付けられたすべての入力コントロールが、その検証コントロールによって指定されている検証規則に準拠しているかどうかを判断します。ページ検証を実行しないようにするには、CausesValidation プロパティを false に設定します。

ユーザー補助

このコントロールに既定でレンダリングされるマークアップは、Web Content Accessibility Guidelines (WCAG) 1.0 の優先度 1 ガイドラインなどのユーザー補助に関する標準に適合しない可能性があります。このコントロールのユーザー補助サポートの詳細については、「ASP.NET コントロールとユーザー補助」を参照してください。

TopicLocation
チュートリアル : ASP.NET ユーザー コントロールによる再利用可能な要素の作成Visual Studio での ASP .NET Web アプリケーションの作成
チュートリアル : ASP.NET ユーザー コントロールによる再利用可能な要素の作成Visual Web Developer でのアプリケーションの作成
チュートリアル : Visual Web Developer での ASP.NET マスタ ページの作成と使用Visual Studio での ASP .NET Web アプリケーションの作成
チュートリアル : Visual Web Developer での ASP.NET マスタ ページの作成と使用Visual Web Developer でのアプリケーションの作成
チュートリアル : Visual Web Developer での基本的な Web ページの作成Visual Studio での ASP .NET Web アプリケーションの作成
チュートリアル : Visual Web Developer での基本的な Web ページの作成Visual Studio ASP .NET での Web アプリケーションの作成
チュートリアル : Web サーバー コントロール用の基本的なコントロール デザイナの作成ASP.NET コントロールの作成
チュートリアル : Web サーバー コントロール用の基本的なコントロール デザイナの作成Visual Studio ASP .NET での Web アプリケーションの作成
チュートリアル : Web フォーム ページにおけるユーザーの入力の検証Visual Studio での ASP .NET Web アプリケーションの作成
チュートリアル : Web フォーム ページにおけるユーザーの入力の検証Visual Web Developer でのアプリケーションの作成
チュートリアル : カスタム ビジネス オブジェクトへのデータ バインディングVisual Studio での ASP .NET Web アプリケーションの作成
チュートリアル : カスタム ビジネス オブジェクトへのデータ バインディングVisual Studio ASP .NET での Web アプリケーションの作成
チュートリアル : テーマを使用した Web サイトのカスタマイズVisual Studio での ASP .NET Web アプリケーションの作成
チュートリアル : テーマを使用した Web サイトのカスタマイズVisual Web Developer でのアプリケーションの作成
チュートリアル: Visual Web Developer でのカスケード スタイル シートのスタイルの操作Visual Studio での ASP .NET Web アプリケーションの作成
チュートリアル: Visual Web Developer で基本的な Web ページの作成dv_vwdcon
チュートリアル: Web サーバー コントロールの基本コントロール デザイナーの作成dv_vwdcon
チュートリアル: Web フォーム ページにおけるユーザー入力の検証dv_vwdcon
チュートリアル: カスタム ビジネス オブジェクトへのバインド データdv_vwdcon
チュートリアル: チュートリアル : ASP.NET ユーザー コントロールによる再利用可能な要素の作成dv_vwdcon
チュートリアル: テーマを使用して Web サイトをカスタマイズします。dv_vwdcon
チュートリアル: 作成と Visual Web Developer で ASP.NET マスター ページを使用します。dv_vwdcon
方法 : ASP.NET Web サーバー コントロールにフォーカスを設定します。dv_vwdcon
方法 : ASP.NET Web サーバー コントロールにフォーカスを設定するASP .NET Web アプリケーションの作成
方法 : ASP.NET Web サーバー コントロールにフォーカスを設定するVisual Studio ASP .NET での Web アプリケーションの作成
方法 : ASP.NET Web ページでイベント ハンドラーを作成します。dv_vwdcon
方法 : ASP.NET Web ページでイベント ハンドラを作成する (Visual Studio)Visual Studio での ASP .NET Web アプリケーションの作成
方法 : ASP.NET Web ページでイベント ハンドラを作成する (Visual Studio)Visual Studio ASP .NET での Web アプリケーションの作成
方法 : ASP.NET Web ページの 1 つのイベント ハンドラに複数のイベントを関連付けるASP .NET Web アプリケーションの作成
方法 : ASP.NET Web ページの 1 つのイベント ハンドラに複数のイベントを関連付けるVisual Studio ASP .NET での Web アプリケーションの作成
方法 : ASP.NET Web ページの単精度浮動小数点型 (Single イベント ハンドラーに複数のイベントを接続します。dv_vwdcon
方法 : Button Web サーバー コントロール イベントに応答するASP .NET Web アプリケーションの作成
方法 : Button Web サーバー コントロール イベントに応答するVisual Studio ASP .NET での Web アプリケーションの作成
方法 : DataList または Repeater 項目内のボタン イベントに応答します。dv_vwdcon
方法 : DataList 項目、Repeater 項目、または GridView 項目のボタン イベントに応答するASP .NET Web アプリケーションの作成
方法 : DataList 項目または Repeater 項目のボタン イベントに応答するVisual Studio ASP .NET での Web アプリケーションの作成
方法 : Web フォーム ページに Button Web サーバー コントロールを追加します。dv_vwdcon
方法 : Web フォーム ページに Button Web サーバー コントロールを追加するASP .NET Web アプリケーションの作成
方法 : Web フォーム ページに Button Web サーバー コントロールを追加する (Visual Studio)Visual Studio での ASP .NET Web アプリケーションの作成
方法 : Web フォーム ページに Button Web サーバー コントロールを追加する (Visual Studio)Visual Studio ASP .NET での Web アプリケーションの作成
方法 : Web フォーム ページに PlaceHolder Web サーバー コントロールを追加するASP .NET Web アプリケーションの作成
方法 : イベントを生成した Web サーバー コントロールを特定するASP .NET Web アプリケーションの作成
方法 : イベントを生成した Web サーバー コントロールを特定するVisual Studio ASP .NET での Web アプリケーションの作成
方法 : クライアント スクリプトで Button Web サーバー コントロール イベントに応答するASP .NET Web アプリケーションの作成
方法 : クライアント スクリプトで Button Web サーバー コントロール イベントに応答するVisual Studio ASP .NET での Web アプリケーションの作成
方法 : クライアント スクリプトのボタン Web サーバー コントロールのイベントに応答します。dv_vwdcon
方法 : データ バインド コントロールのボタン イベントに応答するASP .NET Web アプリケーションの作成
方法 : データ バインド コントロールのボタン イベントに応答するVisual Studio ASP .NET での Web アプリケーションの作成
方法 : データ連結コントロール内のボタン イベントに応答します。dv_vwdcon
方法 : どの Web サーバー コントロール イベントの発生を確認します。dv_vwdcon
方法 : ボタン Web サーバー コントロールのイベントに応答します。dv_vwdcon

Web ページの内容をサーバーにポストバックする、送信 Button コントロールを作成する方法を次のコード例に示します。

Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
    <title>Button Example</title>
<script language="VB" runat="server">
    Sub SubmitBtn_Click(sender As Object, e As EventArgs)
        Message.Text = "Hello World!!"
    End Sub 'SubmitBtn_Click
  </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>
C#
<%@ 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  >
<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>
JScript
<%@ Page Language="JScript" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
    <title>Button Example</title>
<script language="JScript" runat="server">

      function SubmitBtn_Click(sender : Object, e : EventArgs) 
      {
         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 コントロールを作成する方法を次のコード例に示します。

Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head runat="server">
    <title>Button CommandName Example</title>
<script runat="server">

      Sub CommandBtn_Click(sender As Object, e As CommandEventArgs) 

         Select e.CommandName

            Case "Sort"

               ' Call the method to sort the list.
               Sort_List(CType(e.CommandArgument, String))

            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 CType(e.CommandArgument , String) = "" Then

                  ' End the message.
                  Message.Text &= "."

               Else

                  ' Display an error message for the command argument. 
                  Message.Text &= ", however the command argument is not recogized."

               End If                

            Case Else

               ' The command name is not recognized. Display an error message.
               Message.Text = "Command name not recogized."

         End Select

      End Sub

      Sub Sort_List(commandArgument As String)

         Select commandArgument

            Case "Ascending"

               ' Insert code to sort the list in ascending order here.
               Message.Text = "You clicked the Sort Ascending button."

            Case "Descending"

               ' Insert code to sort the list in descending order here.
               Message.Text = "You clicked the Sort Descending button."

            Case Else

               ' The command argument is not recognized. Display an error message.
               Message.Text = "Command argument not recogized."

         End Select

      End Sub

   </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"/>

      &nbsp;

      <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"/>

      &nbsp;

      <asp:Button id="Button4"
           Text="Unknown Command Name"
           CommandName="UnknownName"
           CommandArgument="UnknownArgument"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

      &nbsp;

      <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>

C#
<%@ 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  >
<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"/>

      &nbsp;

      <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"/>

      &nbsp;

      <asp:Button id="Button4"
           Text="Unknown Command Name"
           CommandName="UnknownName"
           CommandArgument="UnknownArgument"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

      &nbsp;

      <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>

アクセス許可

継承階層

System..::.Object
  System.Web.UI..::.Control
    System.Web.UI.WebControls..::.WebControl
      System.Web.UI.WebControls..::.Button
スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム

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 システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 3.5、3.0、2.0、1.1、1.0
参照

参照

その他の技術情報

タグ :


Page view tracker