When to call Page.Validate()

HI All,

I am having an issue with some Validators in my ASP page

I have  a wizard with multiple wizard steps that have different validation groups each

When i call Page.Validate() in onDeactivate event of the Wizard Step the page is not being validated.

But if do that in the Page_Load event it does get validated


is there anything i am doing wrong in this

Thanks
justin_smithAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Juan_BarreraCommented:
Hi,

If moving between steps, you should call Page.Validate in the Wizard.NextButtonClick handler.
Similar approach when handling the Finish step, if needed.
justin_smithAuthor Commented:
thanks for the reply.
there is no default handler for that buttons.
and if even if i have one how would i know whether step's button is clicked at a given instance

further why cant i call page.validate() just anywhere else?

thanks
Juan_BarreraCommented:
Hi,

You can, but it's just a matter of when you want to validate the page.
So, my question is: When do you want to validate the Page?

Usually, in a wizard, you do it before moving to the next step, and that's why I suggested to put it in the NextButtonClick event handler.
Here is a list of all the events you have available: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.wizard_events.aspx




Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

justin_smithAuthor Commented:
Hi Juan,

I tried you suggestion...

When i do this

 protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        if (Wizard1.ActiveStep == WizStep_PaymentDetails)
        {
            Page.Validate("payment_validattion");
        }
    }

it not validating the page...

Still if this is called in Page_Load it works..

I just dont know what i am doing wrong here

Juan_BarreraCommented:
Hi Justin,
Is the event handler being hit? If so, when you say that the page "is not validating",  do you mean that the page is not valid?
I'll show you what I mean:

 protected void Wizard1_Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        if (Wizard1.ActiveStep == WizStep_PaymentDetails)
        {
            Page.Validate("payment_validattion");
            // Check if the Page is valid after validation
            if (Page.IsValid)
            {
                //Do your validated stuff 
            }
            else
            {
                // Cancel the operation                
                e.Cancel = true;
            }
 
        }
 
    }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
justin_smithAuthor Commented:
Hi Barrera,

I tried the codes.. Still no good..

All i had to lately do was keep states in ViewState and call Page.Validate() in Page_Load

This makes me think that validation can only be done in page_load

Juan_BarreraCommented:
Justin,
Certainly I don't know what's wrong with you page, but I can assure you that validation can (and should) be performed in the method that handles the user action.
justin_smithAuthor Commented:
ok cool.. there must be something specific to my page due to possible mistakes...

anyway thanks alot of your help in this regard
Juan_BarreraCommented:
No worries! I hope you find the solution to this problem....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.