473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page.IsValid changes to false after button click

Hi

I have couple of dropdown controls each with a requiredfieldva lidator. 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(ob ject sender, EventArgs e)
{
ddl.ClearSelect ion();
Trace.Write(Pag e.Validators[0].IsValid.ToStri ng()); // returns True
}

protected override void OnPreRender(Eve ntArgs e)
{
Trace.Write(Pag e.Validators[0].IsValid.ToStri ng()); // returns False
base.OnPreRende r(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 6224
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 requiredfieldva lidator. 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(ob ject sender, EventArgs e)
{
ddl.ClearSelect ion();
Trace.Write(Pag e.Validators[0].IsValid.ToStri ng()); // returns True
}

protected override void OnPreRender(Eve ntArgs e)
{
Trace.Write(Pag e.Validators[0].IsValid.ToStri ng()); // returns False
base.OnPreRende r(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 requiredFieldVa lidator will not produce the
exact behavior. Here is a simple test page I used:

========aspx=== =========
<form id="form1" runat="server">
<div>

</div>
<asp:DropDownLi st ID="DropDownLis t1" runat="server">
<asp:ListItem ></asp:ListItem>
<asp:ListItem>a aa</asp:ListItem>
<asp:ListItem>b bb</asp:ListItem>
<asp:ListItem>c cc</asp:ListItem>
</asp:DropDownLis t>
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1" runat="server"
ControlToValida te="DropDownLis t1"
ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
<br />
<br />
<asp:DropDownLi st ID="DropDownLis t2" runat="server">
<asp:ListItem ></asp:ListItem>
<asp:ListItem>a aa</asp:ListItem>
<asp:ListItem>b bb</asp:ListItem>
<asp:ListItem>c cc</asp:ListItem>
</asp:DropDownLis t>
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator2" runat="server"
ControlToValida te="DropDownLis t2"
ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
<br />
<br />
<asp:DropDownLi st ID="DropDownLis t3" runat="server">
<asp:ListItem ></asp:ListItem>
<asp:ListItem>a aa</asp:ListItem>
<asp:ListItem>b bb</asp:ListItem>
<asp:ListItem>c cc</asp:ListItem>
</asp:DropDownLis t>
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator3" runat="server"
ControlToValida te="DropDownLis t3"
ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
<br />
<br />
<asp:Button ID="btnPost" runat="server" onclick="btnPos t_Click"
Text="Post Button" />
<asp:Button ID="btnClear" runat="server" onclick="btnCle ar_Click"
Text="Clear Button" />
</form>
=-========code behind=======
public partial class ValidatePage : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{

}
protected void btnPost_Click(o bject sender, EventArgs e)
{

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

DropDownList1.C learSelection() ;
DropDownList2.C learSelection() ;
DropDownList3.C learSelection() ;

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

protected override void OnPreRender(Eve ntArgs e)
{
base.OnPreRende r(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****@microsof t.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**@newsgroup s.nospam>
References: <uP************ **@TK2MSFTNGP03 .phx.gbl>
<6D************ *************** *******@microso ft.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
Jun 27 '08 #4

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

Similar topics

4
15692
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. When there's a value in the textbox, the (overridden) textchanged event fires and validation is performed. Now I want to turn off autopostback. So I want my contol only validate
5
2530
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 invoked. I am probably wrong about that. If I am suppose to use this function, the edits seemed to be invoked even when you have pressed the cancel and the "CausesValidation" is set to false. Is there a way to get around this (might just be an...
1
6571
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 have a separate submit button which should validate the other fields. This page on MSDN does what I want - almost! ...
1
1493
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 display the text you entered in a text field. There is also a RequiredFieldValidator for the text field so that you get an error if you leave it blank. As long as I have EnableClientScript set to true for the RequiredFieldValidator, if I leave the...
3
1711
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 starts requesting some info, then user press a button, and the same page should show the new field only if validation returns true. But it sounds not so simple to do.
1
4855
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 works, displaying an awesome popup, while other times, it doesn't show a popup at all, but rather just page posts back and the panel becomes visible at the bottom of the page (where it is situated in the designer). what is even stranger to me is that...
1
443
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 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();
2
2217
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. Can the Page.IsValid property be checked in the following code: protected void Page_Load() { if(IsPostBack) {
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.