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:
' your code here
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:
sub abc(sender, e)
' your code here
------ 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
- 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
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.
* 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
* 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
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
message box. And
> change one of the RequiredField property so it won't display on the page
but only in
> the resulting alert.
> P.S. Sorry if I'm not more specific on the property names but my VS
> 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