R
rgparkins
Hi
I am currently having problems with Validators in a user control. I am
creating a wizard sign-up process which have the allocated step
(hyperlinks" at the top of the page. A user can also click
next/previous. Dependant on the current step in the sign-up process I
am loading a new user control as I dont want to have 7-8 pages, just
one page and load the control dynamically.
All is sweet at the moment apart from the validation controls that are
assigned to each user control. Any link that is clicked or button that
is clicked should cause validation on that user control, however I have
performed the following (from another thread)
1. Set EnableClientScript=false on each validator.
2. Set CausesValidation=false on each button that submits the page.
This
prevents the Page.Validate() method from begin called automatically by
the
button.
3. In your click event method, you will call the Validate() method on
each
validator that is associated with the submit button. Then you will test
the
IsValid property to be true on each validator before saving.
I am performing this process BUT as I loop on each validate control
with the allocated user control the isValid IS ALWAYS true. I am sure
its something to do with not loading something or just a simple step I
have missed.. I would appreciate any help on this, some code:
private bool Persist() {
//first check whether we have valid data
AddStockCommon ctrl =
(AddStockCommon)this.FindControl(String.Format("{0}{1}",
ViewState["Context"], ".ascx"));
foreach(Control ct in ctrl.Controls) {
if (ct is BaseValidator) {
BaseValidator validator = (BaseValidator)ct;
validator.Validate();
if (!validator.IsValid) {
return false;
}
}
return true;
}
Many thanks
Richard
I am currently having problems with Validators in a user control. I am
creating a wizard sign-up process which have the allocated step
(hyperlinks" at the top of the page. A user can also click
next/previous. Dependant on the current step in the sign-up process I
am loading a new user control as I dont want to have 7-8 pages, just
one page and load the control dynamically.
All is sweet at the moment apart from the validation controls that are
assigned to each user control. Any link that is clicked or button that
is clicked should cause validation on that user control, however I have
performed the following (from another thread)
1. Set EnableClientScript=false on each validator.
2. Set CausesValidation=false on each button that submits the page.
This
prevents the Page.Validate() method from begin called automatically by
the
button.
3. In your click event method, you will call the Validate() method on
each
validator that is associated with the submit button. Then you will test
the
IsValid property to be true on each validator before saving.
I am performing this process BUT as I loop on each validate control
with the allocated user control the isValid IS ALWAYS true. I am sure
its something to do with not loading something or just a simple step I
have missed.. I would appreciate any help on this, some code:
private bool Persist() {
//first check whether we have valid data
AddStockCommon ctrl =
(AddStockCommon)this.FindControl(String.Format("{0}{1}",
ViewState["Context"], ".ascx"));
foreach(Control ct in ctrl.Controls) {
if (ct is BaseValidator) {
BaseValidator validator = (BaseValidator)ct;
validator.Validate();
if (!validator.IsValid) {
return false;
}
}
return true;
}
Many thanks
Richard