• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 923
  • Last Modified:

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
0
justin_smith
Asked:
justin_smith
  • 5
  • 4
1 Solution
 
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.
0
 
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
0
 
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




0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

0
 
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

0
 
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

0
 
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.
0
 
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
0
 
Juan_BarreraCommented:
No worries! I hope you find the solution to this problem....
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now