Disabling validation in an user control.

Disabling validation in an user control.

am 30.01.2008 14:52:56 von msch.prv

Is there a specific method to disable field validators in a user
control.from within a parent page or does it require an ad hoc
approach? The page attribute ValidateRequest does not seem to be
available in user controls. TIA for any inputs.

RE: Disabling validation in an user control.

am 30.01.2008 17:41:06 von brucebarker

ValidateRequest has nothing to do with validation controls. it enables
validation of postdata to be free of dangerours data (script), only load
postdata to enabled control, and in the case of dropdowns only load postbata
that is in the list.

validation controls can be disabled by setting Enabled=false. you can
recurse the control collection and disable validators:

ControlWalker(myUserControl, delegate(Control ctl)
{
if (ctl is BaseValidator) ctl.Enabled = false;
}

// recurse control collection
public delegate bool ControlWalkerMatcher (Control ctl);
public Control[] ControlWalker(Control ctl, ControlWalkerMatcher matcher)
{
ArrayList list = new ArrayList();
if (matcher(ctl)) list.Add(ctl);
for (int i=0; i < ctl.Controls.Count; ++i)
{
Control[] childList = ControlWalker(ctl.Controls[i],matcher);
if (childList.Length > 0) list.AddRange(childList);
}
return (Control[]) list.ToArray(typeof(Control));
}



-- bruce (sqlwork.com)


"msch.prv@gmail.com" wrote:

> Is there a specific method to disable field validators in a user
> control.from within a parent page or does it require an ad hoc
> approach? The page attribute ValidateRequest does not seem to be
> available in user controls. TIA for any inputs.
>

Re: Disabling validation in an user control.

am 30.01.2008 17:50:31 von gnewsgroup

On Jan 30, 11:41=A0am, bruce barker
wrote:
> ValidateRequest has nothing to do with validation controls. it enables
> validation of postdata to be free of dangerours data (script), only load
> postdata to enabled control, and in the case of dropdowns only load postba=
ta
> that is in the list.
>
> validation controls can be disabled by setting Enabled=3Dfalse. you can
> recurse the control collection and =A0disable validators:
>
> =A0 =A0 ControlWalker(myUserControl, delegate(Control ctl)
> =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0if (ctl is BaseValidator) ctl.Enabled =3D false;
> =A0 =A0 }
>
> =A0 =A0 // recurse control collection
> =A0 =A0 public delegate bool ControlWalkerMatcher (Control ctl);
> =A0 =A0 public Control[] ControlWalker(Control ctl, ControlWalkerMatcher m=
atcher)
> =A0 =A0 {
> =A0 =A0 =A0 =A0 ArrayList list =3D new ArrayList();
> =A0 =A0 =A0 =A0 if (matcher(ctl)) list.Add(ctl);
> =A0 =A0 =A0 =A0 for (int i=3D0; i < ctl.Controls.Count; ++i)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 Control[] childList =3D ControlWalker(ctl.Controls=
[i],matcher);
> =A0 =A0 =A0 =A0 =A0 =A0 if (childList.Length > 0) list.AddRange(childList)=
;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 return (Control[]) list.ToArray(typeof(Control));
> =A0 =A0 }
>
> -- bruce (sqlwork.com)
>
>
>
> "msch....@gmail.com" wrote:
> > Is there a specific method to disable field validators in a user
> > control.from within a parent page or does it require an ad hoc
> > approach? The page attribute ValidateRequest does not seem to be
> > available in user controls. TIA for any inputs.- Hide quoted text -
>
> - Show quoted text -

I've seen this code snippet of yours a couple of times. Could you say
something about the purpose of the delegate there? Thanks. I've
written methods that recursively find controls without a delegate.