本文整理匯總了C#中System.Web.UI.Control.HasControls方法的典型用法代碼示例。如果您正苦於以下問題:C# Control.HasControls方法的具體用法?C# Control.HasControls怎麽用?C# Control.HasControls使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.UI.Control
的用法示例。
在下文中一共展示了Control.HasControls方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: FindChildControl
internal Control FindChildControl(string strid, Control ct)
{
if (ct.ID == strid)
{
return ct;
}
else
{
if (ct.HasControls())
{
foreach (Control ctchild in ct.Controls)
{
Control ctrtn = FindChildControl(strid, ctchild);
if (ctrtn != null)
{
return ctrtn;
}
}
return null;
}
else
{
return null;
}
}
}
示例2: ClearControls
public static void ClearControls(ref Control control)
{
if (control == null)
return;
if (control is TextBox)
{
((TextBox)control).Text = string.Empty;
return;
}
else if (control is DropDownList)
{
((DropDownList)control).SelectedIndex = 0;
return;
}
if (control.HasControls())
{
foreach (Control c in control.Controls)
{
Control ctrl = c;
ClearControls(ref ctrl);
}
}
}
示例3: GetWebValidateBox
private Control GetWebValidateBox(Control ct)
{
if (ct is WebValidate)
{
return ct;
}
else if (ct.HasControls())
{
foreach (Control ctchild in ct.Controls)
{
if (ctchild is WebValidate)
{
return ctchild;
}
else
{
GetWebValidateBox(ctchild);
}
}
return null;
}
else
{
return null;
}
}
示例4: ClearForm
public static void ClearForm(Control container, FormClearOptions option, bool check_nc)
{
try
{
switch (option)
{
case FormClearOptions.ClearAll:
if (check_nc)
{
if (container.ID != null)
if (container.ID.EndsWith("_nc"))
break;
}
if (container.GetType().Equals(typeof(TextBox)))
{
TextBox txtBox = ((TextBox)container);
txtBox.Text = string.Empty;
}
else if (container.GetType().Equals(typeof(DropDownList)))
{
DropDownList ddl = ((DropDownList)container);
ddl.SelectedValue = string.Empty;
}
else if (container.GetType().Equals(typeof(CheckBox)))
{
CheckBox chk = ((CheckBox)container);
chk.Checked = false;
}
else if (container.GetType().Equals(typeof(RadioButtonList)))
{
RadioButtonList rbl = ((RadioButtonList)container);
rbl.SelectedIndex = -1;
}
else if (container.GetType().Equals(typeof(RadioButton)))
{
RadioButton rb = ((RadioButton)container);
rb.Checked = false;
}
else if (container.HasControls())
{
foreach (Control ctrl in container.Controls)
ClearForm(ctrl, option, check_nc);
}
break;
default:
break;
}
}
catch (Exception ex)
{
throw ex;
}
}
示例5: Crawl
private static string Crawl(Control objControl, int intLevel)
{
string result = new string('-',intLevel) + objControl.ClientID + "<br>";
if(objControl.HasControls())
{
foreach(Control c in objControl.Controls)
result += Crawl(c,intLevel + 1);
}
return result;
}
示例6: SetViewState
public static void SetViewState(Control container)
{
container.ViewStateMode= ViewStateMode.Disabled;
if (container.HasControls())
{
foreach(Control ctrl in container.Controls)
{
Control control = ctrl;
SetViewState(control);
}
}
}
示例7: getAllPageControls
/// <summary>
/// Recursively gets every control of the specified root (including root and all it's child controls).
/// Returns the controls as an array of Control objects.
/// </summary>
/// <param name="root">The root control to get child controls for.</param>
/// <returns>An array of all the child controls of root.</returns>
public static Control[] getAllPageControls(Control root)
{
List<Control> list = new List<Control>();
list.Add(root);
if (root.HasControls())
{
foreach (Control control in root.Controls)
{
list.AddRange(getAllPageControls(control));
}
}
return list.ToArray();
}
示例8: FlattenHierachy
public static Control[] FlattenHierachy(Control root)
{
List<Control> list = new List<Control>();
list.Add(root);
if (root.HasControls())
{
foreach (Control control in root.Controls)
{
list.AddRange(FlattenHierachy(control));
}
}
return list.ToArray();
}
示例9: InjectDependenciesRecursiveInternal
private static Control InjectDependenciesRecursiveInternal(IApplicationContext appContext, Control control)
{
if (control is LiteralControl) return control; // nothing to do
ISupportsWebDependencyInjection diControl = control as ISupportsWebDependencyInjection;
if (diControl != null && diControl.DefaultApplicationContext != null)
{
return control; // nothing to do anymore - control cares for itself and its children
}
// "intercept" Control to make it DI-aware
ControlInterceptor.EnsureControlIntercepted(appContext, control);
// if the control is a UserControl, use ApplicationContext from it's physical location
IApplicationContext appContextToUse = appContext;
UserControl userControl = control as UserControl;
if (userControl != null)
{
appContextToUse = GetControlApplicationContext(appContext, userControl);
}
// set ApplicationContext instance
if (control is IApplicationContextAware)
{
((IApplicationContextAware)control).ApplicationContext = appContextToUse;
}
// inject dependencies using control's context
control = (Control)appContextToUse.ConfigureObject(control, control.GetType().FullName);
// and now go for control's children
if (control.HasControls())
{
ControlCollection childControls = control.Controls;
int childCount = childControls.Count;
for (int i = 0; i < childCount; i++)
{
Control c = childControls[i];
if (c is LiteralControl) continue;
Control configuredControl = InjectDependenciesRecursiveInternal(appContext, c);
if (configuredControl != c)
{
ControlAccessor ac = new ControlAccessor(c.Parent);
ac.SetControlAt(configuredControl, i);
}
}
}
return control;
}
示例10: FlattenHierachy
/// <summary>
/// Get all page controls, recursively, ignoring irrelevant controls.
/// </summary>
public static Control[] FlattenHierachy(Control root)
{
if (IgnoreControl(root)) return new Control[0];
var list = new List<Control>() { root };
if (root.HasControls())
{
foreach (Control c in root.Controls)
{
list.AddRange(FlattenHierachy(c));
}
}
return list.ToArray();
}
示例11: HookOnFocus
public void HookOnFocus(Control CurrentControl)
{
//checks if control is one of TextBox, DropDownList, ListBox or Button
if ((CurrentControl is TextBox) ||
(CurrentControl is DropDownList) ||
(CurrentControl is ListBox) ||
(CurrentControl is Button))
//adds a script which saves active control on receiving focus
//in the hidden field __LASTFOCUS.
(CurrentControl as WebControl).Attributes.Add(
"onfocus",
"try{document.getElementById('__LASTFOCUS').value=this.id} catch(e) {}");
//checks if the control has children
if (CurrentControl.HasControls())
//if yes do them all recursively
foreach (Control CurrentChildControl in CurrentControl.Controls)
HookOnFocus(CurrentChildControl);
}
示例12: HasNoControls
/// <summary>
/// Verifies that <paramref name="ctrl"/> has no child controls.
/// </summary>
public static void HasNoControls(Control ctrl)
{
Assert.IsNotNull(ctrl);
Assert.IsFalse(ctrl.HasControls(),
"Control {0} has child controls",
ctrl.ID);
}
示例13: FindByType
Control FindByType (Control parent, Type type)
{
if (!parent.HasControls ())
return null;
foreach (Control c in parent.Controls) {
if (type.IsAssignableFrom (c.GetType ()))
return c;
Control ret = FindByType (c, type);
if (ret != null)
return ret;
}
return null;
}
示例14: findControl
private Control findControl(Control parent, string id)
{
if (parent.HasControls())
{
Control control = parent.FindControl(id);
if (control != null)
{
return control;
}
foreach (Control control2 in parent.Controls)
{
control = this.findControl(control2, id);
if (control != null)
{
return control;
}
}
}
return null;
}
示例15: HasControls
/// <summary>
/// Verifies that <paramref name="ctrl"/> has child controls.
/// </summary>
public static void HasControls(Control ctrl)
{
Assert.IsNotNull(ctrl);
Assert.IsTrue(ctrl.HasControls(),
"Control {0} has no controls",
ctrl.ID);
}