次の方法で共有


BaseValidator.ErrorMessage プロパティ

検証が失敗したときに ValidationSummary コントロールに表示されるエラー メッセージのテキストを取得または設定します。

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

構文

'宣言
<LocalizableAttribute(True)> _
Public Property ErrorMessage As String
'使用
Dim instance As BaseValidator
Dim value As String

value = instance.ErrorMessage

instance.ErrorMessage = value
[LocalizableAttribute(true)] 
public string ErrorMessage { get; set; }
[LocalizableAttribute(true)] 
public:
virtual property String^ ErrorMessage {
    String^ get () sealed;
    void set (String^ value) sealed;
}
/** @property */
public final String get_ErrorMessage ()

/** @property */
public final void set_ErrorMessage (String value)
public final function get ErrorMessage () : String

public final function set ErrorMessage (value : String)
適用できません。

プロパティ値

検証が失敗したときに ValidationSummary コントロールに表示されるエラー メッセージ。既定値は空の文字列 ("") です。このプロパティが設定されていないことを示します。

解説

ValidationSummary コントロールを使用する場合は、ErrorMessage プロパティを使用して、現在の検証コントロールについて検証が失敗した場合に ValidationSummary コントロールに表示するテキストを指定します。検証コントロール内に表示するテキストを指定するには、Text プロパティを使用します。

メモメモ :

Text プロパティを設定せずに ErrorMessage プロパティを設定すると、ErrorMessage プロパティの値も検証コントロール内に表示されます。

デザイナ ツールを使用すると、このプロパティの値を設定した場合にその値をリソース ファイルに自動的に保存できます。詳細については、LocalizableAttributeASP.NET のグローバリゼーションおよびローカリゼーション の各トピックを参照してください。

トピック 場所
チュートリアル : Web フォーム ページにおけるユーザーの入力の検証 Visual Studio での ASP .NET Web アプリケーションの作成
チュートリアル : Web フォーム ページにおけるユーザーの入力の検証 Visual Web Developer でのアプリケーションの作成
方法 : 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 アプリケーションの作成

使用例

ErrorMessage プロパティを使用して、ValidationSummaryRequiredFieldValidatorCompareValidator の各コントロールに異なるメッセージを指定するコード例を次に示します。

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

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

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click
 
    If Page.IsValid Then
    
      MessageLabel.Text = "Page submitted successfully."
    
    Else
    
      MessageLabel.Text = "There is an error on the page."
    
    End If
    
  End Sub
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Validator Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>Validator Example</h3>
     
      Enter a number from 1 to 10.
      <asp:textbox id="NumberTextBox" 
        runat="server"/>

      <asp:rangevalidator id="NumberCompareValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"  
        type="Integer"
        display="Dynamic" 
        errormessage="Please enter a value from 1 to 10."
        maximumvalue="10"
        minimumvalue="1"  
        text="*"
        runat="server"/>

      <asp:requiredfieldvalidator id="TextBoxRequiredValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"
        display="Dynamic" 
        errormessage="Please enter a value."
        text="*"
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        runat="server"/>
 
      <br /><br />
       
      <asp:label id="MessageLabel" 
        runat="server"/>

      <br /><br />

      <asp:validationsummary
        id="ErrorSummary"
        runat="server"/>
 
    </form>
  </body>
</html>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  void Button_Click(Object sender, EventArgs e) 
  {
    if (Page.IsValid)
    {
      MessageLabel.Text = "Page submitted successfully.";
    }
    else
    {
      MessageLabel.Text = "There is an error on the page.";
    }
  }
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Validator Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>Validator Example</h3>
     
      Enter a number from 1 to 10.
      <asp:textbox id="NumberTextBox" 
        runat="server"/>

      <asp:rangevalidator id="NumberCompareValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"  
        type="Integer"
        display="Dynamic" 
        errormessage="Please enter a value from 1 to 10."
        maximumvalue="10"
        minimumvalue="1"  
        text="*"
        runat="server"/>

      <asp:requiredfieldvalidator id="TextBoxRequiredValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"
        display="Dynamic" 
        errormessage="Please enter a value."
        text="*"
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        onclick="Button_Click"
        runat="server"/>
 
      <br /><br />
       
      <asp:label id="MessageLabel" 
        runat="server"/>

      <br /><br />

      <asp:validationsummary
        id="ErrorSummary"
        runat="server"/>
 
    </form>
  </body>
</html>
<%@ Page Language="JScript" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  function Button_Click(sender, e : EventArgs) 
  {
    if (Page.IsValid)
    {
      MessageLabel.Text = "Page submitted successfully.";
    }
    else
    {
      MessageLabel.Text = "There is an error on the page.";
    }
  }
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Validator Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>Validator Example</h3>
     
      Enter a number from 1 to 10.
      <asp:textbox id="NumberTextBox" 
        runat="server"/>

      <asp:rangevalidator id="NumberCompareValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"  
        type="Integer"
        display="Dynamic" 
        errormessage="Please enter a value from 1 to 10."
        maximumvalue="10"
        minimumvalue="1"  
        text="*"
        runat="server"/>

      <asp:requiredfieldvalidator id="TextBoxRequiredValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"
        display="Dynamic" 
        errormessage="Please enter a value."
        text="*"
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        onclick="Button_Click"
        runat="server"/>
 
      <br /><br />
       
      <asp:label id="MessageLabel" 
        runat="server"/>

      <br /><br />

      <asp:validationsummary
        id="ErrorSummary"
        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

参照

関連項目

BaseValidator クラス
BaseValidator メンバ
System.Web.UI.WebControls 名前空間
ValidationSummary
Text