Freigeben über


IValidator.IsValid-Eigenschaft

Ruft bei der Implementierung durch eine Klasse einen Wert ab, der angibt, ob die Prüfung von Benutzereingaben im angegebenen Steuerelement deren Gültigkeit bestätigt hat, oder legt diesen fest.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Property IsValid As Boolean
'Usage
Dim instance As IValidator
Dim value As Boolean

value = instance.IsValid

instance.IsValid = value
bool IsValid { get; set; }
property bool IsValid {
    bool get ();
    void set (bool value);
}
/** @property */
boolean get_IsValid ()

/** @property */
void set_IsValid (boolean value)
function get IsValid () : boolean

function set IsValid (value : boolean)

Eigenschaftenwert

true, wenn der Inhalt gültig ist, andernfalls false.

Beispiel

<HTML>
   <HEAD>
      <script language="VB" runat="server">

         Sub Button_Click(sender As [Object], e As EventArgs)
            ' Generating a random number.
            Dim rand_number As New Random()
            myCompareValidate.ValueToCompare = rand_number.Next(1, 10).ToString()

            ' Set the ErrorMessage.
            myCompareValidate.ErrorMessage = "Try Again!!"
            myCompareValidate.Validate()

            ' Check for Validity of control.
            If myCompareValidate.IsValid And myTextBox.Text <> "" Then
               labelOutput.Text = "You guessed correctly!!"
               labelOutput.ForeColor = System.Drawing.Color.Blue
            Else
               labelOutput.Text = "You guessed poorly"
               labelOutput.ForeColor = System.Drawing.Color.Black
            End If

            labelOutput.Text += "<br><br>" + "The number is: " + _
               myCompareValidate.ValueToCompare
         End Sub 'Button_Click

  </Script>
</HEAD>
    <body>
       <form runat="server" ID="myForm">
          <h3>IValidator Example demonstrating IsValid & ErrorMessage</h3>
          <h5>Guess!! a number between 1 and 10:</h5>
          <asp:TextBox id="myTextBox" runat="server" />
          <asp:CompareValidator id="myCompareValidate"
               ControlToValidate="myTextBox" ValueToCompare="0"
               EnableClientScript="False" Type="Integer" Text="*"
               runat="server" />
          <br>
          <asp:Button Text="Submit" OnClick="Button_Click" runat="server" />
          <br>
          <asp:Label id="labelOutput" runat="server" />
          <br>
          <asp:ValidationSummary id="Summary1" runat="server" />
       </form>
    </body>
</HTML>
<HTML>
  <HEAD>
    <script language="C#" runat="server">

     void Button_Click(Object sender, EventArgs e)
     {
        // Generating the random number.
        Random rand_number = new Random();
        myCompareValidate.ValueToCompare = rand_number.Next(1, 10).ToString();

        // Setting the ErrorMessage.
        myCompareValidate.ErrorMessage="Try Again!!";
        myCompareValidate.Validate();

        // Check for Validity of control.
        if ((myCompareValidate.IsValid) && (myTextBox.Text != ""))
        {
           labelOutput.Text = "You guessed correctly!!";
           labelOutput.ForeColor = System.Drawing.Color.Blue;
        }
        else
        {
           labelOutput.Text =  "You guessed poorly";
           labelOutput.ForeColor = System.Drawing.Color.Black;
        }

        labelOutput.Text += "<br><br>" + "The number is: " +
           myCompareValidate.ValueToCompare;
     }

  </script>
</HEAD>
    <body>
      <form runat="server" ID="myForm">
        <h3>IValidator Example demonstrating IsValid & ErrorMessage</h3>
        <h5>Guess!! a number between 1 and 10 :</h5>
        <asp:TextBox id="myTextBox" runat="server" />
        <asp:CompareValidator id="myCompareValidate"
             ControlToValidate="myTextBox" ValueToCompare="0"
             EnableClientScript="False" Type="Integer" Text="*"
             runat="server" />
        <br>
        <asp:Button Text="Submit" OnClick="Button_Click" runat="server" />
        <br>
        <asp:Label id="labelOutput" runat="server" />
        <br>
        <asp:ValidationSummary id="Summary1" runat="server" />
     </form>
  </body>
</HTML>
<HTML>
  <HEAD>
    <script language="VJ#" runat="server">

    void Button_Click(Object sender, EventArgs e)
    {
        // Generating the random number.
        Random randNumber = new Random();
        myCompareValidate.set_ValueToCompare(
            System.Convert.ToString(randNumber.Next(1, 10)));

        // Setting the ErrorMessage.
        myCompareValidate.set_ErrorMessage("Try Again!!");
        myCompareValidate.Validate();

        // Check for Validity of control.
        if (myCompareValidate.get_IsValid() 
            && (!(myTextBox.get_Text().Equals("")))) {
            labelOutput.set_Text("You guessed correctly!!");
            labelOutput.set_ForeColor(System.Drawing.Color.get_Blue());
        }
        else {
            labelOutput.set_Text("You guessed poorly");
            labelOutput.set_ForeColor(System.Drawing.Color.get_Black());
        }
        labelOutput.set_Text(labelOutput.get_Text() + "<br><br>" 
            + "The number is: " + myCompareValidate.get_ValueToCompare());
    } //Button_Click

  </script>
</HEAD>
    <body>
      <form runat="server" ID="myForm">
        <h3>IValidator Example demonstrating IsValid & ErrorMessage</h3>
        <h5>Guess!! a number between 1 and 10 :</h5>
        <asp:TextBox id="myTextBox" runat="server" />
        <asp:CompareValidator id="myCompareValidate"
             ControlToValidate="myTextBox" ValueToCompare="0"
             EnableClientScript="False" Type="Integer" Text="*"
             runat="server" />
        <br>
        <asp:Button ID="Button1" Text="Submit" OnClick="Button_Click" runat="server" />
        <br>
        <asp:Label id="labelOutput" runat="server" />
        <br>
        <asp:ValidationSummary id="Summary1" runat="server" />
     </form>
  </body>
</HTML>

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

IValidator-Schnittstelle
IValidator-Member
System.Web.UI-Namespace
BaseValidator