Page.IsValid changes to false after button click

Page.IsValid changes to false after button click

am 11.04.2008 19:20:12 von J055

Hi

I have couple of dropdown controls each with a requiredfieldvalidator. I
clear the dropdownlist in the button click event. When the page is rendered
the dropdown validator already flags it's error message. I checked the
IsValid property in the prerender event and it says it's false.

protected void Button_Click(object sender, EventArgs e)
{
ddl.ClearSelection();
Trace.Write(Page.Validators[0].IsValid.ToString()); // returns True
}

protected override void OnPreRender(EventArgs e)
{
Trace.Write(Page.Validators[0].IsValid.ToString()); // returns False
base.OnPreRender(e);
}

What could be happening to change the IsValid property to false? I can't see
anything in my code which would do this. What's the best way to debug this?
What other checks should I be making?

Many thanks
Andrew

RE: Page.IsValid changes to false after button click

am 11.04.2008 19:36:00 von brucebarker

Page.IsValid runs the validation logic. so if you clear a selection, then use
Page.IsValid to run a validation check, it will fail.

-- bruce (sqlwork.com)


"Andrew Jocelyn" wrote:

> Hi
>
> I have couple of dropdown controls each with a requiredfieldvalidator. I
> clear the dropdownlist in the button click event. When the page is rendered
> the dropdown validator already flags it's error message. I checked the
> IsValid property in the prerender event and it says it's false.
>
> protected void Button_Click(object sender, EventArgs e)
> {
> ddl.ClearSelection();
> Trace.Write(Page.Validators[0].IsValid.ToString()); // returns True
> }
>
> protected override void OnPreRender(EventArgs e)
> {
> Trace.Write(Page.Validators[0].IsValid.ToString()); // returns False
> base.OnPreRender(e);
> }
>
> What could be happening to change the IsValid property to false? I can't see
> anything in my code which would do this. What's the best way to debug this?
> What other checks should I be making?
>
> Many thanks
> Andrew
>
>
>

Re: Page.IsValid changes to false after button click

am 12.04.2008 12:29:30 von J055

Hi Bruce

That doesn't seem to be the case in my simple test with a single validator
on a page. The Page.IsValid value does not change how ever many times I call
it. However it does change in my project page which contains a FormView
control with a number of UserControls. What I don't seem to be able to do is
find out where or why it's changing.

Any ideas?

Thanks
Andrew

Re: Page.IsValid changes to false after button click

am 14.04.2008 05:43:32 von stcheng

Hi Andrew,

According to your description, I've performed some tests, it seems a simple
page with dropdownlist and requiredFieldValidator will not produce the
exact behavior. Here is a simple test page I used:

========aspx============







aaa
bbb
ccc

ControlToValidate="DropDownList1"
ErrorMessage="RequiredFieldValidator">







aaa
bbb
ccc

ControlToValidate="DropDownList2"
ErrorMessage="RequiredFieldValidator">







aaa
bbb
ccc

ControlToValidate="DropDownList3"
ErrorMessage="RequiredFieldValidator">





Text="Post Button" />
Text="Clear Button" />



=-========code behind=======
public partial class ValidatePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnPost_Click(object sender, EventArgs e)
{

}
protected void btnClear_Click(object sender, EventArgs e)
{
Response.Write("
Page.IsValid: " + Page.Validators[0].IsValid);

DropDownList1.ClearSelection();
DropDownList2.ClearSelection();
DropDownList3.ClearSelection();

Response.Write("
Page.IsValid: " + Page.Validators[0].IsValid);
}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

Response.Write("
Page.IsValid: " + Page.Validators[0].IsValid);
}
}
=======================

It seems as long as the page postback(when I click the Clear Button) and
passed client-side validation, the server-side validation won't return
false after I "ClearSelection" on the dropdownlists.

As you mentioned that there are other forms and usercontrols, I'm wondering
whether some input entry in them may cause the problem. Have you tried
removing some of them to isolate the behavior?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx .
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------
>From: "Andrew Jocelyn"
>References:
<6D954008-5C17-474E-BF47-37C0038671E6@microsoft.com>
>Subject: Re: Page.IsValid changes to false after button click
>Date: Sat, 12 Apr 2008 11:29:30 +0100
>
>Hi Bruce
>
>That doesn't seem to be the case in my simple test with a single validator
>on a page. The Page.IsValid value does not change how ever many times I
call
>it. However it does change in my project page which contains a FormView
>control with a number of UserControls. What I don't seem to be able to do
is
>find out where or why it's changing.
>
>Any ideas?
>
>Thanks
>Andrew
>
>
>