11 out of 12 rated this helpful - Rate this topic

Page.IsValid Property

Gets a value indicating whether page validation succeeded.

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

public bool IsValid { get; }
/** @property */
public boolean get_IsValid ()

public function get IsValid () : boolean

Not applicable.

Property Value

true if page validation succeeded; otherwise, false.
Exception type Condition

HttpException

The IsValid property is called before validation has occurred.

For this property to return true, all validation server controls in the current validation group must validate successfully. You should check this property only after you have called the Page.Validate method, or set the CausesValidation property to true in the OnServerClick event handler for an ASP.NET server control that initiates form processing. These server controls include the Button, HtmlButton, HtmlInputButton, HtmlInputImage, ImageButton, and LinkButton classes.

If you force validation of a validation group using the Validate method, then all validation controls in the specified validation group must validate successfully as well.

The following code example demonstrates using the IsValid property to set up a conditional statement. If the property returns true, the Text property of the lblOutput control is set to "Page is valid!" Otherwise, it is set to "Some of the required fields are empty."

private void ValidateBtn_Click(Object Sender, EventArgs E)
{
    Page.Validate();
    if (Page.IsValid == true)
        lblOutput.Text = "Page is Valid!";
    else
        lblOutput.Text = "Some required fields are empty.";
}

void ValidateBtn_Click(Object sender, EventArgs e)
{
    this.get_Page().Validate();
    if (this.get_Page().get_IsValid() == true)
        lblOutput.set_Text("Page is Valid!");
    else
        lblOutput.set_Text("Some of the required fields are empty.");
}

function ValidateBtn_Click(Sender, e : EventArgs) 
{
    Page.Validate();
    if (Page.IsValid == true) 
        lblOutput.Text = "Page is Valid!";
    else
        lblOutput.Text = "Some required fields are empty";
}

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ