By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,028 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,028 IT Pros & Developers. It's quick & easy.

Disabling validation in an user control.

P: n/a
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.
Jan 30 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)
"ms******@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.
Jan 30 '08 #2

P: n/a
On Jan 30, 11:41*am, bruce barker
<brucebar...@discussions.microsoft.comwrote:
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....@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.
Jan 30 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.