Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / DynamicEntity.cs / 1305376 / DynamicEntity.cs
using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Globalization; using System.Web.DynamicData.Util; using System.Web.Resources; using System.Web.UI; using System.Web.UI.WebControls; namespace System.Web.DynamicData { [ToolboxBitmap(typeof(DynamicEntity), "DynamicEntity.bmp")] public class DynamicEntity : Control { private HttpContextBase _context; [ DefaultValue(DataBoundControlMode.ReadOnly), Category("Behavior"), ResourceDescription("DynamicEntity_Mode") ] public DataBoundControlMode Mode { get { var value = ViewState["Mode"]; return value != null ? (DataBoundControlMode)value : DataBoundControlMode.ReadOnly; } set { ViewState["Mode"] = value; } } [ DefaultValue(""), Category("Behavior"), ResourceDescription("DynamicControlFieldCommon_UIHint") ] public string UIHint { get { return (string)ViewState["UIHint"] ?? String.Empty; } set { ViewState["UIHint"] = value; } } [ Category("Behavior"), DefaultValue(""), Themeable(false), ResourceDescription("DynamicControlFieldCommon_ValidationGroup") ] public string ValidationGroup { get { return (string)ViewState["ValidationGroup"] ?? String.Empty; } set { ViewState["ValidationGroup"] = value; } } private new HttpContextBase Context { get { return _context ?? new HttpContextWrapper(HttpContext.Current); } } public DynamicEntity() { } // for unit testing internal DynamicEntity(HttpContextBase context) : this() { _context = context; } [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", MessageId = "0#")] protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (DesignMode) { return; } MetaTable table = MetaTableHelper.FindMetaTable(this, Context); if (table == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.DynamicEntity_ControlNeedsToExistInAContextSupportingDynamicData, this.ID)); } EntityTemplateFactory entityTemplateFactory = table.Model.EntityTemplateFactory; EntityTemplateUserControl entityTemplateControl = entityTemplateFactory.CreateEntityTemplate(table, Mode, UIHint); if (entityTemplateControl == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.DynamicEntity_CantFindTemplate, table.Name, entityTemplateFactory.TemplateFolderVirtualPath)); } entityTemplateControl.Mode = Mode; entityTemplateControl.ValidationGroup = ValidationGroup; entityTemplateControl.Table = table; Controls.Add(entityTemplateControl); } protected override void Render(HtmlTextWriter writer) { if (DesignMode) { writer.Write("[" + GetType().Name + "]"); } else { base.Render(writer); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Globalization; using System.Web.DynamicData.Util; using System.Web.Resources; using System.Web.UI; using System.Web.UI.WebControls; namespace System.Web.DynamicData { [ToolboxBitmap(typeof(DynamicEntity), "DynamicEntity.bmp")] public class DynamicEntity : Control { private HttpContextBase _context; [ DefaultValue(DataBoundControlMode.ReadOnly), Category("Behavior"), ResourceDescription("DynamicEntity_Mode") ] public DataBoundControlMode Mode { get { var value = ViewState["Mode"]; return value != null ? (DataBoundControlMode)value : DataBoundControlMode.ReadOnly; } set { ViewState["Mode"] = value; } } [ DefaultValue(""), Category("Behavior"), ResourceDescription("DynamicControlFieldCommon_UIHint") ] public string UIHint { get { return (string)ViewState["UIHint"] ?? String.Empty; } set { ViewState["UIHint"] = value; } } [ Category("Behavior"), DefaultValue(""), Themeable(false), ResourceDescription("DynamicControlFieldCommon_ValidationGroup") ] public string ValidationGroup { get { return (string)ViewState["ValidationGroup"] ?? String.Empty; } set { ViewState["ValidationGroup"] = value; } } private new HttpContextBase Context { get { return _context ?? new HttpContextWrapper(HttpContext.Current); } } public DynamicEntity() { } // for unit testing internal DynamicEntity(HttpContextBase context) : this() { _context = context; } [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", MessageId = "0#")] protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (DesignMode) { return; } MetaTable table = MetaTableHelper.FindMetaTable(this, Context); if (table == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.DynamicEntity_ControlNeedsToExistInAContextSupportingDynamicData, this.ID)); } EntityTemplateFactory entityTemplateFactory = table.Model.EntityTemplateFactory; EntityTemplateUserControl entityTemplateControl = entityTemplateFactory.CreateEntityTemplate(table, Mode, UIHint); if (entityTemplateControl == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.DynamicEntity_CantFindTemplate, table.Name, entityTemplateFactory.TemplateFolderVirtualPath)); } entityTemplateControl.Mode = Mode; entityTemplateControl.ValidationGroup = ValidationGroup; entityTemplateControl.Table = table; Controls.Add(entityTemplateControl); } protected override void Render(HtmlTextWriter writer) { if (DesignMode) { writer.Write("[" + GetType().Name + "]"); } else { base.Render(writer); } } } } // 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
- CompositeDataBoundControl.cs
- ScrollProviderWrapper.cs
- EncoderReplacementFallback.cs
- ProgressBarRenderer.cs
- PathFigure.cs
- RuntimeConfigLKG.cs
- PermissionSet.cs
- MessagePartDescription.cs
- Storyboard.cs
- BinaryWriter.cs
- FormatSettings.cs
- ValueUnavailableException.cs
- SignatureDescription.cs
- QueryAccessibilityHelpEvent.cs
- FactoryMaker.cs
- ExpressionLink.cs
- SessionPageStatePersister.cs
- PackageDigitalSignature.cs
- RequestQueryProcessor.cs
- SqlNodeAnnotation.cs
- ManagementObject.cs
- RegistryPermission.cs
- DefaultObjectMappingItemCollection.cs
- WindowsFont.cs
- ObjectSelectorEditor.cs
- TrustSection.cs
- XmlDataSource.cs
- xml.cs
- StrongNameIdentityPermission.cs
- AllowedAudienceUriElement.cs
- CatalogPartChrome.cs
- ResourceExpressionBuilder.cs
- PageBreakRecord.cs
- ToolTip.cs
- InfoCardArgumentException.cs
- HtmlShimManager.cs
- QuaternionIndependentAnimationStorage.cs
- XpsFontSerializationService.cs
- ImageButton.cs
- ProfileBuildProvider.cs
- Method.cs
- ActivationArguments.cs
- PtsHelper.cs
- XmlChoiceIdentifierAttribute.cs
- ObsoleteAttribute.cs
- TextTreeObjectNode.cs
- RSAPKCS1SignatureFormatter.cs
- GridViewUpdateEventArgs.cs
- ClrPerspective.cs
- bidPrivateBase.cs
- TextParaClient.cs
- SvcMapFile.cs
- UInt64Storage.cs
- FunctionMappingTranslator.cs
- SplitterCancelEvent.cs
- DiscoveryClientElement.cs
- ComPersistableTypeElementCollection.cs
- ColorContext.cs
- XmlSchemaObject.cs
- PackageRelationshipCollection.cs
- WindowsIdentity.cs
- ProjectionNode.cs
- TouchesCapturedWithinProperty.cs
- RenderDataDrawingContext.cs
- COMException.cs
- BindingWorker.cs
- CachingHintValidation.cs
- x509store.cs
- ColorContext.cs
- ForwardPositionQuery.cs
- EntityViewGenerationAttribute.cs
- BooleanToSelectiveScrollingOrientationConverter.cs
- XpsS0ValidatingLoader.cs
- AuthenticationModuleElement.cs
- ServicePoint.cs
- RootNamespaceAttribute.cs
- ThreadStaticAttribute.cs
- DataFormats.cs
- FontStretches.cs
- DataErrorValidationRule.cs
- PaperSize.cs
- UriTemplateTrieLocation.cs
- DynamicMethod.cs
- StreamInfo.cs
- brushes.cs
- ModelVisual3D.cs
- MemberRelationshipService.cs
- ErrorRuntimeConfig.cs
- TextServicesDisplayAttribute.cs
- XmlSerializableWriter.cs
- TemplateEditingService.cs
- BaseCodePageEncoding.cs
- SelectionEditor.cs
- XmlAutoDetectWriter.cs
- GridViewRow.cs
- SynchronizationContextHelper.cs
- StackOverflowException.cs
- HttpStreams.cs
- DictionaryTraceRecord.cs
- SecurityResources.cs