Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / GlobalDataBindingHandler.cs / 1 / GlobalDataBindingHandler.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design {
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using Microsoft.Win32;
using System.Diagnostics;
using System.Reflection;
using System.Web.UI;
//using DataBinding = System.Web.UI.DataBinding;
///
///
///
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
internal sealed class GlobalDataBindingHandler {
public static readonly EventHandler Handler = new EventHandler(GlobalDataBindingHandler.OnDataBind);
private static Hashtable dataBindingHandlerTable;
///
///
///
private GlobalDataBindingHandler() {
}
///
///
///
private static Hashtable DataBindingHandlerTable {
get {
if (dataBindingHandlerTable == null) {
dataBindingHandlerTable = new Hashtable();
}
return dataBindingHandlerTable;
}
}
///
///
///
public static void OnDataBind(object sender, EventArgs e) {
Debug.Assert(sender is Control, "DataBindings can only be present on Controls.");
Control control = (Control)sender;
// check if this control has any data-bindings
IDataBindingsAccessor dataBindingsAccessor = (IDataBindingsAccessor)sender;
if (dataBindingsAccessor.HasDataBindings == false) {
return;
}
// check if the control type has an associated data-binding handler
DataBindingHandlerAttribute handlerAttribute =
(DataBindingHandlerAttribute)TypeDescriptor.GetAttributes(sender)[typeof(DataBindingHandlerAttribute)];
if ((handlerAttribute == null) || (handlerAttribute.HandlerTypeName.Length == 0)) {
return;
}
// components in the designer/container do not get handled here; the
// designer for that control handles it in its own special way
ISite site = control.Site;
IDesignerHost designerHost = null;
if (site == null) {
Page page = control.Page;
if (page != null) {
site = page.Site;
}
else {
// When the designer is working on a UserControl instead of a Page
Control parent = control.Parent;
// We shouldn't have to walk up the parent chain a whole lot - maybe a couple
// of levels on the average
while ((site == null) && (parent != null)) {
if (parent.Site != null) {
site = parent.Site;
}
parent = parent.Parent;
}
}
}
if (site != null) {
designerHost = (IDesignerHost)site.GetService(typeof(IDesignerHost));
}
if (designerHost == null) {
Debug.Fail("Did not get back an IDesignerHost");
return;
}
// non-top level components, such as controls within templates do not have designers
// these are the only things that need the data-binding handler stuff
IDesigner designer = designerHost.GetDesigner(control);
if (designer != null) {
return;
}
// get the handler and cache it the first time around
DataBindingHandler dataBindingHandler = null;
try {
string handlerTypeName = handlerAttribute.HandlerTypeName;
dataBindingHandler = (DataBindingHandler)DataBindingHandlerTable[handlerTypeName];
if (dataBindingHandler == null) {
Type handlerType = Type.GetType(handlerTypeName);
if (handlerType != null) {
dataBindingHandler = (DataBindingHandler)Activator.CreateInstance(handlerType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, null, null);
DataBindingHandlerTable[handlerTypeName] = dataBindingHandler;
}
}
}
catch (Exception ex) {
Debug.Fail(ex.ToString());
return;
}
// finally delegate to it to handle this particular control
if (dataBindingHandler != null) {
dataBindingHandler.DataBindControl(designerHost, control);
}
}
}
}
// 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
- ResponseStream.cs
- GB18030Encoding.cs
- MultiBindingExpression.cs
- TextDecorationCollection.cs
- ToggleButtonAutomationPeer.cs
- ValidationHelpers.cs
- MemoryMappedView.cs
- DrawingDrawingContext.cs
- GenericRootAutomationPeer.cs
- SafeProcessHandle.cs
- BlurEffect.cs
- XmlSerializerImportOptions.cs
- ToolboxCategory.cs
- ClientSettingsProvider.cs
- DependencyObjectProvider.cs
- IntSecurity.cs
- SchemaImporterExtensionElement.cs
- ApplicationSecurityInfo.cs
- NavigationPropertyEmitter.cs
- XmlValidatingReader.cs
- RelOps.cs
- OutputCacheSettingsSection.cs
- CodeCatchClause.cs
- EventSinkActivity.cs
- Main.cs
- GPRECT.cs
- DesignTimeTemplateParser.cs
- NameScopePropertyAttribute.cs
- PeerToPeerException.cs
- WasAdminWrapper.cs
- ChannelManager.cs
- FigureHelper.cs
- SqlDataSourceAdvancedOptionsForm.cs
- BatchServiceHost.cs
- TypedDataSourceCodeGenerator.cs
- GeometryHitTestResult.cs
- XPathNodePointer.cs
- SqlTypeConverter.cs
- QueryOutputWriter.cs
- Debugger.cs
- SelectionProcessor.cs
- NativeMethods.cs
- EncodingDataItem.cs
- ObjectDataSourceView.cs
- XDeferredAxisSource.cs
- SqlConnectionFactory.cs
- SqlCaseSimplifier.cs
- SerializationInfo.cs
- BrowserDefinition.cs
- METAHEADER.cs
- SelectionList.cs
- ConnectorRouter.cs
- XMLDiffLoader.cs
- TextEditorSelection.cs
- ObjectAnimationBase.cs
- Animatable.cs
- VerticalAlignConverter.cs
- PingOptions.cs
- XmlIlVisitor.cs
- NativeMethods.cs
- SessionEndedEventArgs.cs
- HttpHandlerAction.cs
- Executor.cs
- XPathNavigatorKeyComparer.cs
- CharacterShapingProperties.cs
- MembershipUser.cs
- PrimarySelectionGlyph.cs
- BaseParser.cs
- TextBox.cs
- MenuItemCollectionEditorDialog.cs
- PinnedBufferMemoryStream.cs
- LayoutInformation.cs
- TranslateTransform3D.cs
- CacheMemory.cs
- SQlBooleanStorage.cs
- GetWorkflowTree.cs
- Int64.cs
- TextDecorationUnitValidation.cs
- AssemblyHash.cs
- DataGridViewTopRowAccessibleObject.cs
- XsdBuildProvider.cs
- ReflectEventDescriptor.cs
- AttributeConverter.cs
- VariableQuery.cs
- ProcessProtocolHandler.cs
- SqlCommandSet.cs
- OledbConnectionStringbuilder.cs
- _Semaphore.cs
- TypedDataSetSchemaImporterExtensionFx35.cs
- NestPullup.cs
- TimeoutException.cs
- EditorPartCollection.cs
- MediaTimeline.cs
- ConvertersCollection.cs
- DeviceFiltersSection.cs
- ThicknessConverter.cs
- RemoteDebugger.cs
- MediaScriptCommandRoutedEventArgs.cs
- X509WindowsSecurityToken.cs
- XamlToRtfWriter.cs