Page showing as not valid

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I have a page that is showing as:

Page.IsValid = False

on postback when my submit button is pressed but none of my Validators have
fired so there is no error message.

How do I find out what is making the Page invalid?

Thanks,

Tom
 
Well, here are some questions/tests that might help you and some of us in
the newsgroups answer your question:

1. How do you know that none of the Validators fired?

2. What is the value for the CausesValidation property of any Buttons,
TextBoxes, DropDownLists, or other controls that might have that property on
your page?

It may also help us answer your question if we could see your code so that
we know exactly what is happening on your page, so you may want to post it.
Good Luck!
 
Nathan Sokalski said:
Well, here are some questions/tests that might help you and some of us in
the newsgroups answer your question:

1. How do you know that none of the Validators fired?

Because I have no error messages. I have only 2 Validators

<td ><asp:TextBox ID="RequestedStartDate" Columns="12"
runat="server"/>
(Applicant will have the option to request an alternative date)
<asp:RequiredFieldValidator runat="server"
ControlToValidate="RequestedStartDate"
Display="Dynamic"
Type="Date" text="<br>Start Date Required"/>
<asp:RegularExpressionValidator
ControlToValidate="RequestedStartDate"
ValidationExpression="^(([1-9])|(0[1-9])|(1[0-2]))\/(([1-9])|(0[1-9])|(1[0-9])|(2[0-9])|(3[0-1]))\/((\d{2})|(\d{4}))$"
Display="Dynamic"
2. What is the value for the CausesValidation property of any Buttons,
TextBoxes, DropDownLists, or other controls that might have that property
on your page?

I don't have anything set for the CausesValidation of any objects. I have 2
textboxes and about 10 dropdowns.
It may also help us answer your question if we could see your code so that
we know exactly what is happening on your page, so you may want to post
it.

It would be a little hard to post as it is a large page which is a One page
(not code-behind) style.

The test is:

trace.warn("Before Page.IsValid if Page.IsValid = " & Page.IsValid )
If not Page.IsValid then
Exit Sub
End if

In the above code Page.IsValid is set to false.

Thanks,

Tom
 
I think I found the problem but not why. It has to do with the fact that
HTML comments don't seem to work with asp.net.
I have the following page:
********************************************************
<%@ Page Language="VB" trace="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" Inherits="MyFunctions.Page" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="MyFunctions" %>
<Script runat="server">
Sub Page_Load(s as Object, e as EventArgs)
Dim item as ListItem
Dim oLabel as Label
if not IsPostBack then
ValidateDate.ValueToCompare = DateTime.Today.ToString("yyyy-MM-dd")
end if
end sub

Sub SubmitNewHire_Click(s as Object, e as ImageClickEventArgs)
Dim pageError as Boolean = false
trace.warn("Before Page.IsValid if Page.IsValid = " & Page.IsValid & "
PageError = " & pageError)
If not Page.IsValid then
Exit Sub
End if
End Sub
</script>
<html>
<head>
<title>:: Staffing Workshop ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body id="myBody" runat="server">
<form runat="server">
<asp:TextBox ID="RequestedStartDate" Columns="12" runat="server"/>
<!-- <asp:CompareValidator runat="server" ID="ValidateDate"
ControlToValidate="RequestedStartDate"
Operator="GreaterThan"
Display="Dynamic"
Type="Date" text="<br>Invalid Start Date"/>
-->
<asp:ImageButton ImageUrl="../../buttons/submit_0.gif"
OnClick="SubmitNewHire_Click" runat="server"/>
</form>
</body>
</html>
*************************************************************

I should get an error here.

I have the Validator commented out but the line:

ValidateDate.ValueToCompare = DateTime.Today.ToString("yyyy-MM-dd")

Still seems to work. I should get an error that says that there is no such
object ValidateDate (as it is commented out). If I delete the Validator - I
get the error.

If I take out the ValidateDate.ValueToCompare line, I get an error saying
that '' is not a valid date. Why would I get that error if this Validator
is commented out? I get this error as I am entering the page.

This was why I was getting the error.

I was putting in yesterdays date (which the validator says I can't do). So
the page is showing as not valid. But since the Validator is commented
out - the error message doesn't show (which it does if I don't comment it
out).

What gives?

Thanks,

Tom
 
When commenting out an ASP.NET tag, you need to use <%-- --%> rather than
<!-- -->. This should solve your problem. Good Luck!
 
Nathan Sokalski said:
When commenting out an ASP.NET tag, you need to use <%-- --%> rather
than <!-- -->. This should solve your problem. Good Luck!

That was the problem.

But why would it be set up that way? Why doesn't MS just use the normall
HTML comments.

Thanks,

Tom
 
If the server code would remove all HTML comments, there would be no way
to put an HTML comment in the code.
 
Those are the comments used in Classic ASP, so they kept the same ones to
make ASP.NET easier for developers to learn. Also, if you use Visual Studio
..NET there are buttons that you can use to comment or uncomment something.
These buttons will use the correct character depending on whether you are
editing the *.aspx file or the codebehind file.
 
Back
Top