Disabling validation in an user control.

M

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.
 
B

bruce barker

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,matcher);
if (childList.Length > 0) list.AddRange(childList);
}
return (Control[]) list.ToArray(typeof(Control));
}



-- bruce (sqlwork.com)
 
G

gnewsgroup

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,matcher);
            if (childList.Length > 0) list.AddRange(childList);
        }
        return (Control[]) list.ToArray(typeof(Control));
    }

-- bruce (sqlwork.com)



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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top