Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / ControlHelper.cs / 1 / ControlHelper.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design {
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.CodeDom;
using System.Runtime.InteropServices;
using System.Collections.Generic;
internal static class ControlHelper {
///
/// Finds a control with a given ID starting with the siblings of the given control.
/// This method walk up naming container boundaries to find the control.
///
internal static Control FindControl(IServiceProvider serviceProvider, Control control, string controlIdToFind) {
if (String.IsNullOrEmpty(controlIdToFind)) {
throw new ArgumentNullException("controlIdToFind");
}
while (control != null) {
if (control.Site == null || control.Site.Container == null) {
return null;
}
IComponent component = control.Site.Container.Components[controlIdToFind];
if (component != null) {
return component as Control;
}
// Try to get the parent of this control's naming container
IDesignerHost designerHost = (IDesignerHost)control.Site.GetService(typeof(IDesignerHost));
if (designerHost == null) {
return null;
}
ControlDesigner designer = designerHost.GetDesigner(control) as ControlDesigner;
if (designer == null || designer.View == null || designer.View.NamingContainerDesigner == null) {
return null;
}
control = designer.View.NamingContainerDesigner.Component as Control;
}
if (serviceProvider != null) {
IDesignerHost host = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
if (host != null) {
IContainer container = host.Container;
if (container != null) {
return container.Components[controlIdToFind] as System.Web.UI.Control;
}
}
}
return null;
}
internal delegate bool IsValidComponentDelegate(IComponent component);
internal static IList GetAllComponents(IComponent component, IsValidComponentDelegate componentFilter) {
List foundComponents = new List();
while (component != null) {
IList components = GetComponentsInContainer(component, componentFilter);
foundComponents.AddRange(components);
// Walk up to the naming container to get the next level of controls
IDesignerHost designerHost = (IDesignerHost)component.Site.GetService(typeof(IDesignerHost));
ControlDesigner designer = designerHost.GetDesigner(component) as ControlDesigner;
component = null;
if (designer != null && designer.View != null && designer.View.NamingContainerDesigner != null) {
component = designer.View.NamingContainerDesigner.Component;
}
}
return foundComponents;
}
private static IList GetComponentsInContainer(IComponent component, IsValidComponentDelegate componentFilter) {
System.Diagnostics.Debug.Assert(component != null);
List foundComponents = new List();
if ((component.Site != null) && (component.Site.Container != null)) {
foreach (IComponent comp in component.Site.Container.Components) {
if (componentFilter(comp) && !Marshal.IsComObject(comp)) {
PropertyDescriptor modifierProp = TypeDescriptor.GetProperties(comp)["Modifiers"];
if (modifierProp != null) {
MemberAttributes modifiers = (MemberAttributes)modifierProp.GetValue(comp);
if ((modifiers & MemberAttributes.AccessMask) == MemberAttributes.Private) {
// must be declared as public or protected
continue;
}
}
foundComponents.Add(comp);
}
}
}
return foundComponents;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ChannelSettingsElement.cs
- SettingsPropertyIsReadOnlyException.cs
- WhitespaceSignificantCollectionAttribute.cs
- AutomationEvent.cs
- AutomationInteropProvider.cs
- SystemIcmpV4Statistics.cs
- AuthenticationException.cs
- ChtmlCalendarAdapter.cs
- CategoryGridEntry.cs
- ObjectStateManagerMetadata.cs
- BufferManager.cs
- TrackBar.cs
- XpsS0ValidatingLoader.cs
- WeakEventManager.cs
- Property.cs
- NetTcpSecurity.cs
- XmlIgnoreAttribute.cs
- UserCancellationException.cs
- SiteOfOriginContainer.cs
- AsyncSerializedWorker.cs
- DiscoveryDocumentSerializer.cs
- XmlDictionaryReaderQuotas.cs
- ChangeDirector.cs
- WmpBitmapEncoder.cs
- PersistenceException.cs
- Transform3D.cs
- ScriptReference.cs
- ConvertEvent.cs
- GeneralTransformCollection.cs
- TemplateControlParser.cs
- XmlReader.cs
- EncodingNLS.cs
- ObfuscateAssemblyAttribute.cs
- SaveFileDialog.cs
- SQLDateTime.cs
- QueryCacheEntry.cs
- DataServiceStreamProviderWrapper.cs
- CheckBoxPopupAdapter.cs
- _SslSessionsCache.cs
- FontFamily.cs
- VisualStyleElement.cs
- JapaneseLunisolarCalendar.cs
- DelegateSerializationHolder.cs
- CompileLiteralTextParser.cs
- TabletCollection.cs
- TimeSpanParse.cs
- DataListItem.cs
- GroupBox.cs
- ExternalException.cs
- SiblingIterators.cs
- ResumeStoryboard.cs
- XmlSchemaComplexContent.cs
- MatrixConverter.cs
- Ops.cs
- Membership.cs
- OpenTypeLayoutCache.cs
- PixelFormat.cs
- ProgressBarRenderer.cs
- AliasedSlot.cs
- Int16Storage.cs
- XmlDocumentSerializer.cs
- ImageAnimator.cs
- TrackingStringDictionary.cs
- ChooseAction.cs
- CharAnimationBase.cs
- PaintValueEventArgs.cs
- SafeWaitHandle.cs
- SuppressMergeCheckAttribute.cs
- FactoryId.cs
- X509CertificateChain.cs
- SpellerHighlightLayer.cs
- XPathCompileException.cs
- MembershipValidatePasswordEventArgs.cs
- FilterableAttribute.cs
- StrokeNodeOperations2.cs
- ContentElementCollection.cs
- SchemaObjectWriter.cs
- NativeMethods.cs
- MaxSessionCountExceededException.cs
- ReadOnlyHierarchicalDataSourceView.cs
- TextReader.cs
- VisualStateChangedEventArgs.cs
- ChannelManager.cs
- CodeAccessSecurityEngine.cs
- SelectionProviderWrapper.cs
- CompiledQueryCacheEntry.cs
- HScrollBar.cs
- DataGridViewCellEventArgs.cs
- SimpleWebHandlerParser.cs
- DependencyPropertyHelper.cs
- FileDialogCustomPlace.cs
- WebServiceHandler.cs
- NetworkInformationPermission.cs
- CmsInterop.cs
- DataViewManager.cs
- X509CertificateValidationMode.cs
- Table.cs
- CodeTypeOfExpression.cs
- CellIdBoolean.cs
- RegionIterator.cs