473,394 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Page.IsValid changes to false after button click

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
Jun 27 '08 #1
3 6166
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
Jun 27 '08 #2
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
Jun 27 '08 #3
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============
<form id="form1" runat="server">
<div>

</div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>aaa</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>
<asp:ListItem>ccc</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DropDownList1"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<br />
<br />
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>aaa</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>
<asp:ListItem>ccc</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="DropDownList2"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<br />
<br />
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>aaa</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>
<asp:ListItem>ccc</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="DropDownList3"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="btnPost" runat="server" onclick="btnPost_Click"
Text="Post Button" />
<asp:Button ID="btnClear" runat="server" onclick="btnClear_Click"
Text="Clear Button" />
</form>
=-========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("<br/>Page.IsValid: " + Page.Validators[0].IsValid);

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

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

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

Response.Write("<br/>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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "Andrew Jocelyn" <j0**@newsgroups.nospam>
References: <uP**************@TK2MSFTNGP03.phx.gbl>
<6D**********************************@microsoft.co m>
>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
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: owingruters | last post by:
Hi all, I've created an User control. It's an extension of a textbox wich has some extra properties so that validation becomes a lot faster. The control wordks great if autopostback is on....
5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
1
by: Liz | last post by:
I have a page with several dropdownlists, several text boxes and several buttons which perform calculations. I need to validate one dropdownlist (not the whole page) with the click of one button. I...
1
by: bennett | last post by:
At http://www.brainjammer.com/testing/validator_test.aspx I have a text field where you can enter text, and a button where if you click the button, it sets the value of a label below it, to...
3
by: vodafone | last post by:
Hy all I've a little problem. I need to write a dynamic page that render control according to validation status return from previous control validation status. To be clear, I've page that...
1
by: mbruyns | last post by:
i have been trying (and sometimes succeeding) to use the modalpopupextender to show various panels of controls on my asp pages. the strange problem that i keep on running into is that sometimes it...
1
by: Andrew Jocelyn | last post by:
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...
2
by: =?Utf-8?B?R2FyeSBMYXJpbWVy?= | last post by:
I an asp.net web page with a simple form and a Submit button. Form entries are validated client side, but as a back up I would also like to validate server side, but not sure where to do it code....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.