ASP.NET Page.IsValid in VB.NET

Here, we will see how to use Page.IsValid property in VB.NET.
  • 5084

Here, we see how to use Page.IsValid property in VB.NET. ships with a couple of validator controls that allow you to determine whether the value of the input controls they are validating is valid. The Page.IsValid property tells you indicating whether page validation succeeded. True if page validation succeeded otherwise false.


If the property returns true, the Text property of the Output control is set to "Page is valid!" Otherwise, it is set to "Some of the required fields are empty.

 If (Page.IsValid) Then
        lblOutput.Text = "Page is Valid!"
        lblOutput.Text = "Some required fields are empty."
 End If

It can be called only after the Page.Validate method is called. By using this property, you can add logic to your page to determine whether to proceed with the PostBack event or not. So, in addition to relying on client side validation, it is also important that you call Page.IsValid when handling the postback event.

For Example

In this example we will see what happened when we click on the Button2.


    <form id="form1" runat="server">


        <asp:TextBox ID="TextBox1" runat="server" ValidationGroup="MyValidationGroup"></asp:TextBox>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"ControlToValidate="TextBox1"



field is required!" ValidationGroup="MyValidationGroup"></asp:RequiredFieldValidator>

        <br />

        <asp:Button ID="Button1" runat="server" Text="Button1"ValidationGroup="MyValidationGroup"

            CausesValidation="true" />

        <br />

        <br />

        <asp:TextBox ID="TextBox2" runat="server" ValidationGroup="AnotherValidationGroup"></asp:TextBox>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"ControlToValidate="TextBox2"



field is required!" ValidationGroup="AnotherValidationGroup"></asp:RequiredFieldValidator>

        <br />

        <asp:Button ID="Button2" runat="server" Text="Button2"ValidationGroup="AnotherValidationGroup"

            OnClick="Button2_Click" />




Now double click on the Button2 and add the following code.

Protected Sub Button2_Click(ByVal sender As ObjectByVal e As EventArgs)


        If Not Page.IsValid Then


        End If

        Response.Write("Button was clicked at " & DateTime.Now.ToShortTimeString())

    End Sub


Now run the application and enter some value in TextBoxes. 



Now click on the Button2.




More Articles

© 2020 DotNetHeaven. All rights reserved.