473,406 Members | 2,371 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,406 software developers and data experts.

How do you check if validate has been called.

I get the following message from one of my buttons where I have
CauseValidation=false.

Page.IsValid cannot be called before validation has taken place

In my routine I need to do:

if Not IsValid then
exit sub
end if

This is because I have a custom validator on some of my fields and I need to
check this as the function will run regardless of the results of the cusom
validators.

The problem is that I may press the button before any validation has taken
place, which is why I get the error.

Is there a way to check if any validation has taken place, such that I might
do something like:

if some validation done then
if Not IsValid then
exit sub
end if
end if

Thanks,

Tom
Nov 19 '05 #1
8 5383
Are you trying to check Page.IsValid inside of your custom validation events?
This will give back incorrect results since the order of your validators
and the other validators isn't guarenteed.

If you're trying to do this in Page_Load then just call Page.Validate() first.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I get the following message from one of my buttons where I have
CauseValidation=false.

Page.IsValid cannot be called before validation has taken place

In my routine I need to do:

if Not IsValid then
exit sub
end if
This is because I have a custom validator on some of my fields and I
need to check this as the function will run regardless of the results
of the cusom validators.

The problem is that I may press the button before any validation has
taken place, which is why I get the error.

Is there a way to check if any validation has taken place, such that I
might do something like:

if some validation done then
if Not IsValid then
exit sub
end if
end if
Thanks,

Tom


Nov 19 '05 #2
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:31**********************@msnews.microsoft.com ...
Are you trying to check Page.IsValid inside of your custom validation
events? This will give back incorrect results since the order of your
validators and the other validators isn't guarenteed.
It is a routine that is called by one of my buttons that does not cause
Validation. But I do want to check if the page has been validated and if
NOT - do one thing. If it has gone through validation - do something else.

I don't want to Validate, just check if it has been validated. But I can't
look at Page.IsValid if validation has not been called.

Tom
If you're trying to do this in Page_Load then just call Page.Validate()
first.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I get the following message from one of my buttons where I have
CauseValidation=false.

Page.IsValid cannot be called before validation has taken place

In my routine I need to do:

if Not IsValid then
exit sub
end if
This is because I have a custom validator on some of my fields and I
need to check this as the function will run regardless of the results
of the cusom validators.

The problem is that I may press the button before any validation has
taken place, which is why I get the error.

Is there a way to check if any validation has taken place, such that I
might do something like:

if some validation done then
if Not IsValid then
exit sub
end if
end if
Thanks,

Tom


Nov 19 '05 #3
> I don't want to Validate, just check if it has been validated. But I
can't look at Page.IsValid if validation has not been called.


Validate always happens after Page_Load but before your server change events
and server click events.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #4
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:38**********************@msnews.microsoft.com ...
I don't want to Validate, just check if it has been validated. But I
can't look at Page.IsValid if validation has not been called.
Validate always happens after Page_Load but before your server change

events and server click events.
That isn't the question. I am not concerned about at what point in a page
load Validation is done.

My problem is that I press a submit button, that I specifically tell not to
validate, that calls a routine where I am checking IsValid. I am getting an
error because if the page was never validated, this is an error (to check
IsValid).

What I want to do in the routine is check if validation has been done before
I check "IsValid", so I don't get the error.

Thanks,

Tom
-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #5
> My problem is that I press a submit button, that I specifically tell
not to validate, that calls a routine where I am checking IsValid. I
am getting an error because if the page was never validated, this is
an error (to check IsValid).

What I want to do in the routine is check if validation has been done
before I check "IsValid", so I don't get the error.


You can always check the sender of the event, cast it to a Button and check
CausesValidation to get the results you want. If it's true then you can check
IsValid if it's false then you can't.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #6
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:42**********************@msnews.microsoft.com ...
My problem is that I press a submit button, that I specifically tell
not to validate, that calls a routine where I am checking IsValid. I
am getting an error because if the page was never validated, this is
an error (to check IsValid).

What I want to do in the routine is check if validation has been done
before I check "IsValid", so I don't get the error.
You can always check the sender of the event, cast it to a Button and
check CausesValidation to get the results you want. If it's true then you
can check IsValid if it's false then you can't.


But that doesn't tell me if another button causes validation or not.

For example, if I have 2 buttons, button A doesn't call validation and
button B does.

If button A is pushed before button B and I do a "if Not IsValid", then I
will get an error.

Testing button A to see if it causes validation doesn't tell me if another
button has caused it or not.

Tom
-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #7
> But that doesn't tell me if another button causes validation or not.

Hmm, ok. Well, I'm sorry that I'm just not getting what you're looking for.
:(
For example, if I have 2 buttons, button A doesn't call validation and
button B does.
Do you have them calling the same server side event handler or different
events handlers?
If button A is pushed before button B and I do a "if Not IsValid",
then I will get an error.
But once you click one button that causes the postback. You don't tend to
get two button clicks on a single postback. If you have two roundtrips (meaning
two button clicks) then it's possible that between postbacks the values of
controls have changed, thus the valid state may have changed. I'm not sure
that helps you, since I don't know what you need.
Testing button A to see if it causes validation doesn't tell me if
another button has caused it or not.


Again, sorry I don't toally grok what what you're trying to do... but perhaps
the validation architecture just doesn't support it. *shrug*

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #8
The issue is solved in http://forums.asp.net/thread/1527065.aspx

It explains following code snippet:

using System.Web;
using System.Web.UI;
using System.Reflection;

public class PageUtil
{
public static bool IsPageValidated()
{
Page page = HttpContext.Current.Handler as Page;
if (page == null) throw new HttpException("This method can be called only in classes derived from System.Web.UI.Page");
FieldInfo fieldValidated = typeof(Page).GetField("_validated", BindingFlags.Instance | BindingFlags.NonPublic);
return (bool)fieldValidated.GetValue(page);
}
}

From http://www.developmentnow.com/g/8_20...en-called-.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Jan 11 '07 #9

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

Similar topics

6
by: Xerxes | last post by:
Hi, how can I check if an input field in a form is defined? I create the field dynamically, so it could or could not be in the form. TIA.
5
by: Steve Wylie | last post by:
I am constructing an HTML questionnaire and one of the questions requires people to rate some choices from 1 to 5, where 1 is their favourite and 5 is their least favourite: Car Bus Taxi cab...
5
by: Anthony Robinson | last post by:
Consider the following tables: CREATE TABLE "AIMD "."CHANNELSESSION" ( "CHANNELSESSIONID" DECIMAL(13,0) NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH +1 , INCREMENT BY +1 , CACHE 20 ) ,...
2
by: John H | last post by:
Hi, How can i just use the XmlDocument object to validate an xml instanace against a schema referenced inside the xml instance? The Load method seems to not validate it against the schema. ...
5
by: eyoung | last post by:
I have a function to check a string to make sure it is 6 digites using the trigger onBlur="CkFrmt(this)" Problem is I've got 4 fields in a row...if I enter a wrong number in the first and hit tab...
18
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning...
9
by: webrod | last post by:
Hi all, how can I check a user/password in a LDAP ? I don't want to connect with this user, I would like to connect to LDAP with a ADMIN_LOG/ADMIN_PWD, then do a query to find the user and...
1
by: Alexio | last post by:
I am a newbie to this and am having a problem with validation and keeping data that has been entered in other fields when submitting the form. For the check boxes, I need a minimum of one selected....
2
by: thj | last post by:
Hi. I've got this form that I'm trying to validate: <form id="periodForm" action="" method="post"> <p> Periode: <input id="startDate" name="startDate" type="text" size="7" value="<%=...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.