次の方法で共有


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 に設定します。

メモメモ :

PostBackUrl プロパティを使用して別のページにポストバックしている場合は、CausesValidation プロパティを false に設定する必要があります。別のページにポストバックする場合は、明示的に検証を行う必要があります。例については、PostBackUrl プロパティの解説を参照してください。

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

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

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

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

使用例

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

セキュリティに関するメモセキュリティに関するメモ :

この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。詳細については、「スクリプトによる攻略の概要」を参照してください。

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" > 

<head runat="server">
    <title> Button CausesValidation Example </title>
<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 id="form1" 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" %>

<!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 CausesValidation Example </title>
<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 id="form1" 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>

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

Button クラス
Button メンバ
System.Web.UI.WebControls 名前空間
Page.Validate
ValidationGroup

その他の技術情報

検証の新機能
Button Web サーバー コントロール