Validation and Page.IsValid

Validation and Page.IsValid

Post by Mike Moore ( » Sun, 11 Aug 2002 12:39:13

Hi Rod,

You provided several excerpts from your web form. I think a few important
pieces didn't get included. In any case, here are some comments.

suggest moving these lines to the top of your page as recommended by the
page directives documentation:   "Directives can be located anywhere in an
aspx file, but standard practice is to place them at the beginning of the

** Page directives and script tags are used in the HTML portion of a web
form. Web forms can also have a separate file called a "code-behind". In
Visual Studio, if you right-click the page in the Solution Explorer window
and select View Code, to read and edit the code-behind.

** Your excerpts show invalid syntax for creating a procedure inside a
script block. Since your script tag shows runat=server, you could move this
code to the code-behind. However, your description of the behavior you
would like, indicates that we need some client-side script to display a
message box (called an "alert" in java script).

Your code snippet shows:
sub abc()
<script ...>
   ' your code here
End Sub

The procedure starts before the script block and the script block is not
terminated. The correct syntax for a procedure in a VB script block is:
<script ...>
sub abc(sender, e)
   ' your code here
End Sub

------  Simple Validation
* Start a new web form
* Add a text box, a required field validator and a button
* Set the validator's properties
   - Use the drop list in the "control to validate" property to select the
text box
   - Change the Error Message property to something appropriate,
      such as "First name is a required field"
* Save and build the solution
* View the page and click the button with the textbox blank to see the
error message
Notice that it does NOT send the page to the server. This validation
happens on the client. The end user gets a faster response and your server
has less work to do.

-----  Adding A Message Box
[Thank you Daniel Lemire]
* Continue with the web form you just created
* Add a Validation Summary control
* In the summary control's properties, set ShowMessageBox to true
* At some point after you have this working, experiment with the
ShowMessageBox and ShowSummary properties. The show message box shows the
list of errors in a message box and the show summary shows the list of
errors on the page. You might want just one or just the other.
* Similarly, experiment with the required field validator's Display
property to determine the behavior you want.

----- NOTES
* While you are in the properties window, you can click on one of the
properties to select it and then press F1 to get help on that property. You
can also select a control on the form and press F1 for more general help on
the control.

* Unless you use a custom validation control, you don't need to add
server-side code to repeat the validation after it arrives on the server.
The validation controls automatically perform server-side validation
regardless of whether you enable client-side validation. The client-side
validation is faster and results in less work for your server. However,
malicious users can bypass client-side validation, so the controls
automatically perform the validation again on the server.

Thank you, Mike Moore
Microsoft, ASP.NET

This posting is provided "AS IS" with no warranties, and confers no rights

> Date: Fri, 09 Aug 2002 14:55:58 -0400

> Subject: Re: Validation and Page.IsValid
> Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols

> If all validations are on the client side you can use a

ValidationSummary. You'll
> need to change one property for the ValidationSummary to make it a
message box. And
> change one of the RequiredField property so it won't display on the page
but only in
> the resulting alert.

> Daniel

> P.S. Sorry if I'm not more specific on the property names but my VS
computer is
> beeing fixed up.

> > Date: Fri, 09 Aug 2002 14:30:14 -0400

> > Subject: Validation and Page.IsValid
> > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols

> > I'd like to test validation and if data is not valid I'd like either a
> > pop up windows to appear or an HTML window with instructions to enter
> > valid data.  Below is what I've tired and though it doesn't update db
> > required, it doesn't bring up the html page.

> > Thanks for any help
> > ---------------------

> > Sub submit_Click(sender as Object, e as EventArgs)

> > <script language="VB" runat="server">
> > If (Page.IsValid) Then

> > ... code to add fields to db...

> > Else
> >       Response.Redirect("mistake.html")
> > End If
> >    End Sub

> > ... here's the webform control
> > <strong>First Name</strong>
> > <strong>(Required)</strong><br>
> > <asp:textbox id="FirstName" runat="server" size="40" />

> > <asp:RequiredFieldValidator id="RequiredFieldValidator1"
> > ControlToValidate="FirstName" Display="Dynamic"  Width="100%"
> > runat=server  ErrorMessage="This field is


1. CustomValidator.IsValid value not pushed up to Page.IsValid

My custom validator checks a value and sets its IsValid property
accordingly.  In the case when it is set to false, how does that get rolled
into the Page.IsValid property, which is read only?  After the
ServerValidate action happens, the buttons OnClick event happens and
continues on its merry way because Page.IsValid = true even though the
custom validator's IsValid property = false

2. Logging capabilities

3. Determening if Page.IsValid from client side script

4. PGPFreeware 7.03

5. Page.IsValid performs a postback for a toolbarbutton web control

6. Unhappy with 2.05

7. Determening if Page.IsValid from client side script

8. HD Info for 16/6000 - Part 1

9. "Page.IsValid" doesn't work IT'S URGENT!!!

10. Page.IsValid

11. Page.IsValid returns false in User controls

12. HttpClientCertificate IsValid method