Disabling validation in an user control.

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.
msch.prv [ Mi, 30 Januar 2008 14:52 ] [ ID #1919906 ]

RE: Disabling validation in an user control.

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 [at] 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.
>
brucebarker [ Mi, 30 Januar 2008 17:41 ] [ ID #1919940 ]

Re: Disabling validation in an user control.

On Jan 30, 11:41=A0am, bruce barker
<brucebar... [at] discussions.microsoft.com> 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.... [at] 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.
gnewsgroup [ Mi, 30 Januar 2008 17:50 ] [ ID #1919942 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » Disabling validation in an user control.

Vorheriges Thema: Can someone help me sort this one out and quick?
Nächstes Thema: Accessing a Hidden HTML field in the OnInit() method