Button.CausesValidation プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Button.CausesValidation プロパティの意味・解説 

Button.CausesValidation プロパティ

Button コントロールがクリックされたときに検証を実行するかどうかを示す値を取得または設定します。

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

<ThemeableAttribute(False)> _
Public Overridable Property
 CausesValidation As Boolean
Dim instance As Button
Dim value As Boolean

value = instance.CausesValidation

instance.CausesValidation = value
[ThemeableAttribute(false)] 
public virtual bool CausesValidation { get;
 set; }
[ThemeableAttribute(false)] 
public:
virtual property bool CausesValidation {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_CausesValidation ()

/** @property */
public void set_CausesValidation (boolean value)
public function get CausesValidation
 () : boolean

public function set CausesValidation
 (value : boolean)

プロパティ値
Button コントロールがクリックされたときに検証を実行する場合は true。それ以外の場合は false。既定値は true です。

解説解説

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

CausesValidation プロパティを使用して Button コントロールがクリックされたときに、クライアントとサーバーの両方で検証を実行するかどうかを指定または確認できます。検証を実行しないようにするには、CausesValidation プロパティを false に設定します。

通常、このプロパティはリセット ボタンまたは消去ボタンがクリックされたときに検証が実行されないように、これらのボタンに対しては false に設定されます。

CausesValidation プロパティの値が true に設定されている場合は、ValidationGroup プロパティを使用して、Button コントロールによって発生する検証の対象となる検証グループの名前を指定することもできます。

このプロパティを、テーマまたはスタイル シート テーマを使用して設定することはできません。詳細については、ThemeableAttribute、ASP.NET のテーマとスキンの概要 の各トピックを参照してください。

TopicLocation
方法 : ASP.NET サーバー コントロールに必要なエントリを検証するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールのカスタム検証メッセージを表示するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールのデータベースの値を検証するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールのデータ型を検証するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールのパターンに対して検証するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールの値の範囲を検証するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールの固有の値を検証するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールの埋め込み先メッセージのレイアウトを指定するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールの有効性をプログラムでテストするASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールの検証エラー メッセージの書式を設定するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールの検証を無効にするASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールをカスタム関数で検証するASP .NET Web アプリケーションの作成
方法 : ASP.NET サーバー コントロールをプログラムで検証するASP .NET Web アプリケーションの作成
使用例使用例

CausesValidation プロパティを使用して、ページ検証が実行されないようにする方法を次のコード例に示します。Validate メソッドが各検証コントロールを別々にアクティブにする点に注目してください。

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

<html> 

<head>

   <script runat="server">

      Sub SubmitButton_Click(sender As Object,
 e As EventArgs)
         
         ' Determine which button was clicked.
         Select Case (CType(sender, Button)).ID

            Case "CityQueryButton"

               ' Validate only the controls used for the city query.
               CityReqValidator.Validate()

               ' Take the appropriate action if the controls pass validation.
 
               If CityReqValidator.IsValid Then
           
                  Message.Text = "You have chosen to run a query
 for the following city: " & _ 
                     CityTextBox.Text
               
               End If

            Case "StateQueryButton"

               ' Validate only the controls used for the state query.
               StateReqValidator.Validate()

               ' Take the appropriate action if the controls pass validation.
               If StateReqValidator.IsValid Then
               
                  Message.Text = "You have chosen to run a query
 for the following state: " & _ 
                     StateTextBox.Text
               
               End If

            Case Else

               ' If the button clicked isn't recognized, erase the message
 on the page.
               Message.Text = ""

         End Select
        
      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> Button CausesValidation Example </h3>

      <table border="1" cellpadding="10">
         <tr>
            <td>
               <b>Enter city to query.</b> <br>
               <asp:TextBox ID="CityTextBox" 
                    runat="server"/>
               <asp:RequiredFieldValidator ID="CityReqValidator"
                    ControlToValidate="CityTextBox"
                    ErrorMessage="<br>Please enter a city."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <asp:Button ID="CityQueryButton"
                    Text="Submit"
                    CausesValidation="False"
                    OnClick="SubmitButton_Click"
                    runat="server"/>
            </td>
         </tr>

         <tr>
            <td>
               <b>Enter state to query.</b> <br>
               <asp:TextBox ID="StateTextBox" 
 
                    runat="server"/>
               <asp:RequiredFieldValidator ID="StateReqValidator"
                    ControlToValidate="StateTextBox"
                    ErrorMessage="<br>Please enter a state."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <asp:Button ID="StateQueryButton"
                    Text="Submit"
                    CausesValidation="False"
                    OnClick="SubmitButton_Click"
                    runat="server"/>
            </td>
         </tr>

      </table>

      <br><br>

      <asp:Label ID="Message"
           runat="Server"/>

   </form>

</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>

<html> 

<head>

   <script runat="server">

      void SubmitButton_Click(Object sender, EventArgs e)
      {
         
         // Determine which button was clicked.
         switch(((Button)sender).ID)
         {

            case "CityQueryButton":

               // Validate only the controls used for the city query.
               CityReqValidator.Validate();

               // Take the appropriate action if the controls pass validation.
 
               if (CityReqValidator.IsValid)
               {
                  Message.Text = "You have chosen to run a query for
 the following city: " + 
                     CityTextBox.Text;
               }

               break;

            case "StateQueryButton":

               // Validate only the controls used for the state query.
               StateReqValidator.Validate();

               // Take the appropriate action if the controls pass validation.
               if (StateReqValidator.IsValid)
               {
                  Message.Text = "You have chosen to run a query for
 the following state: " + 
                     StateTextBox.Text;
               }

               break;

            default:

               // If the button clicked isn't recognized, erase the
 message on the page.
               Message.Text = "";

               break;

         }
        
      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> Button CausesValidation Example </h3>

      <table border="1" cellpadding="10">
         <tr>
            <td>
               <b>Enter city to query.</b> <br>
               <asp:TextBox ID="CityTextBox" 
                    runat="server"/>
               <asp:RequiredFieldValidator ID="CityReqValidator"
                    ControlToValidate="CityTextBox"
                    ErrorMessage="<br>Please enter a city."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <asp:Button ID="CityQueryButton"
                    Text="Submit"
                    CausesValidation="False"
                    OnClick="SubmitButton_Click"
                    runat="server"/>
            </td>
         </tr>

         <tr>
            <td>
               <b>Enter state to query.</b> <br>
               <asp:TextBox ID="StateTextBox"  
                    runat="server"/>
               <asp:RequiredFieldValidator ID="StateReqValidator"
                    ControlToValidate="StateTextBox"
                    ErrorMessage="<br>Please enter a state."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <asp:Button ID="StateQueryButton"
                    Text="Submit"
                    CausesValidation="False"
                    OnClick="SubmitButton_Click"
                    runat="server"/>
            </td>
         </tr>

      </table>

      <br><br>

      <asp:Label ID="Message"
           runat="Server"/>

   </form>

</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Button.CausesValidation プロパティ」の関連用語

Button.CausesValidation プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Button.CausesValidation プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS