Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do you check if validate has been called.

Reply
Thread Tools

How do you check if validate has been called.

 
 
tshad
Guest
Posts: n/a
 
      03-31-2005
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


 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      03-31-2005
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
>




 
Reply With Quote
 
 
 
 
tshad
Guest
Posts: n/a
 
      04-06-2005
"Brock Allen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ...
> 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
>>

>
>
>



 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      04-06-2005
> 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



 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      04-10-2005
"Brock Allen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ...
> > 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
>
>
>



 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      04-11-2005
> 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



 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      04-11-2005
"Brock Allen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ...
>> 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
>
>
>



 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      04-11-2005
> 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





 
Reply With Quote
 
Marian Kostal
Guest
Posts: n/a
 
      01-11-2007
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...een-called-.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to verify/validate that only image has been uploaded Ankur ASP .Net 4 01-12-2009 04:50 PM
Check that a buffer has been completely written Paolo C++ 5 07-07-2006 02:07 AM
The printing has been stopped and this job has been add to the queu? dejola Computer Support 6 12-30-2005 03:26 AM
I need help I has been over 6 months since I've been able to do the system check for updates Marc Computer Support 8 07-25-2005 07:04 PM
NEWBIE: check if page has been changed Marco Krechting Java 2 01-07-2005 11:15 AM



Advertisments