Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / UI / WebControls / ControlParameter.cs / 1 / ControlParameter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.ComponentModel;
using System.Data;
using System.Web.UI.WebControls;
using System.Security.Permissions;
///
/// Represents a Parameter that gets its value from a control's property.
///
[
DefaultProperty("ControlID"),
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class ControlParameter : Parameter {
///
/// Creates an instance of the ControlParameter class.
///
public ControlParameter() {
}
///
/// Creates an instance of the ControlParameter class with the specified parameter name and control ID.
///
public ControlParameter(string name, string controlID) : base(name) {
ControlID = controlID;
}
///
/// Creates an instance of the ControlParameter class with the specified parameter name, control ID, and property name.
///
public ControlParameter(string name, string controlID, string propertyName) : base(name) {
ControlID = controlID;
PropertyName = propertyName;
}
///
/// Creates an instance of the ControlParameter class with the specified parameter name, database type,
/// control ID, and property name.
///
public ControlParameter(string name, DbType dbType, string controlID, string propertyName)
: base(name, dbType) {
ControlID = controlID;
PropertyName = propertyName;
}
///
/// Creates an instance of the ControlParameter class with the specified parameter name, type, control ID, and property name.
///
public ControlParameter(string name, TypeCode type, string controlID, string propertyName) : base(name, type) {
ControlID = controlID;
PropertyName = propertyName;
}
///
/// Used to clone a parameter.
///
protected ControlParameter(ControlParameter original) : base(original) {
ControlID = original.ControlID;
PropertyName = original.PropertyName;
}
///
/// The ID of the control to get the value from.
///
[
DefaultValue(""),
IDReferenceProperty(),
RefreshProperties(RefreshProperties.All),
TypeConverter(typeof(ControlIDConverter)),
WebCategory("Control"),
WebSysDescription(SR.ControlParameter_ControlID),
]
public string ControlID {
get {
object o = ViewState["ControlID"];
if (o == null)
return String.Empty;
return (string)o;
}
set {
if (ControlID != value) {
ViewState["ControlID"] = value;
OnParameterChanged();
}
}
}
///
/// The name of the control's property to get the value from.
/// If none is specified, the ControlValueProperty attribute of the control will be examined to determine the default property name.
///
[
DefaultValue(""),
TypeConverter(typeof(ControlPropertyNameConverter)),
WebCategory("Control"),
WebSysDescription(SR.ControlParameter_PropertyName),
]
public string PropertyName {
get {
object o = ViewState["PropertyName"];
if (o == null)
return String.Empty;
return (string)o;
}
set {
if (PropertyName != value) {
ViewState["PropertyName"] = value;
OnParameterChanged();
}
}
}
///
/// Creates a new ControlParameter that is a copy of this ControlParameter.
///
protected override Parameter Clone() {
return new ControlParameter(this);
}
///
/// Returns the updated value of the parameter.
///
protected override object Evaluate(HttpContext context, Control control) {
if (control == null) {
return null;
}
string controlID = ControlID;
string propertyName = PropertyName;
if (controlID.Length == 0) {
throw new ArgumentException(SR.GetString(SR.ControlParameter_ControlIDNotSpecified, Name));
}
Control foundControl = DataBoundControlHelper.FindControl(control, controlID);
if (foundControl == null) {
throw new InvalidOperationException(SR.GetString(SR.ControlParameter_CouldNotFindControl, controlID, Name));
}
ControlValuePropertyAttribute controlValueProp = (ControlValuePropertyAttribute)TypeDescriptor.GetAttributes(foundControl)[typeof(ControlValuePropertyAttribute)];
// If no property name is specified, use the ControlValuePropertyAttribute to determine which property to use.
if (propertyName.Length == 0) {
if ((controlValueProp != null) && (!String.IsNullOrEmpty(controlValueProp.Name))) {
propertyName = controlValueProp.Name;
}
else {
throw new InvalidOperationException(SR.GetString(SR.ControlParameter_PropertyNameNotSpecified, controlID, Name));
}
}
// Get the value of the property
object value = DataBinder.Eval(foundControl, propertyName);
// Convert the value to null if this is the default property and the value is the property's default value
if (controlValueProp != null &&
String.Equals(controlValueProp.Name, propertyName, StringComparison.OrdinalIgnoreCase) &&
controlValueProp.DefaultValue != null &&
controlValueProp.DefaultValue.Equals(value)) {
return null;
}
return value;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.ComponentModel;
using System.Data;
using System.Web.UI.WebControls;
using System.Security.Permissions;
///
/// Represents a Parameter that gets its value from a control's property.
///
[
DefaultProperty("ControlID"),
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class ControlParameter : Parameter {
///
/// Creates an instance of the ControlParameter class.
///
public ControlParameter() {
}
///
/// Creates an instance of the ControlParameter class with the specified parameter name and control ID.
///
public ControlParameter(string name, string controlID) : base(name) {
ControlID = controlID;
}
///
/// Creates an instance of the ControlParameter class with the specified parameter name, control ID, and property name.
///
public ControlParameter(string name, string controlID, string propertyName) : base(name) {
ControlID = controlID;
PropertyName = propertyName;
}
///
/// Creates an instance of the ControlParameter class with the specified parameter name, database type,
/// control ID, and property name.
///
public ControlParameter(string name, DbType dbType, string controlID, string propertyName)
: base(name, dbType) {
ControlID = controlID;
PropertyName = propertyName;
}
///
/// Creates an instance of the ControlParameter class with the specified parameter name, type, control ID, and property name.
///
public ControlParameter(string name, TypeCode type, string controlID, string propertyName) : base(name, type) {
ControlID = controlID;
PropertyName = propertyName;
}
///
/// Used to clone a parameter.
///
protected ControlParameter(ControlParameter original) : base(original) {
ControlID = original.ControlID;
PropertyName = original.PropertyName;
}
///
/// The ID of the control to get the value from.
///
[
DefaultValue(""),
IDReferenceProperty(),
RefreshProperties(RefreshProperties.All),
TypeConverter(typeof(ControlIDConverter)),
WebCategory("Control"),
WebSysDescription(SR.ControlParameter_ControlID),
]
public string ControlID {
get {
object o = ViewState["ControlID"];
if (o == null)
return String.Empty;
return (string)o;
}
set {
if (ControlID != value) {
ViewState["ControlID"] = value;
OnParameterChanged();
}
}
}
///
/// The name of the control's property to get the value from.
/// If none is specified, the ControlValueProperty attribute of the control will be examined to determine the default property name.
///
[
DefaultValue(""),
TypeConverter(typeof(ControlPropertyNameConverter)),
WebCategory("Control"),
WebSysDescription(SR.ControlParameter_PropertyName),
]
public string PropertyName {
get {
object o = ViewState["PropertyName"];
if (o == null)
return String.Empty;
return (string)o;
}
set {
if (PropertyName != value) {
ViewState["PropertyName"] = value;
OnParameterChanged();
}
}
}
///
/// Creates a new ControlParameter that is a copy of this ControlParameter.
///
protected override Parameter Clone() {
return new ControlParameter(this);
}
///
/// Returns the updated value of the parameter.
///
protected override object Evaluate(HttpContext context, Control control) {
if (control == null) {
return null;
}
string controlID = ControlID;
string propertyName = PropertyName;
if (controlID.Length == 0) {
throw new ArgumentException(SR.GetString(SR.ControlParameter_ControlIDNotSpecified, Name));
}
Control foundControl = DataBoundControlHelper.FindControl(control, controlID);
if (foundControl == null) {
throw new InvalidOperationException(SR.GetString(SR.ControlParameter_CouldNotFindControl, controlID, Name));
}
ControlValuePropertyAttribute controlValueProp = (ControlValuePropertyAttribute)TypeDescriptor.GetAttributes(foundControl)[typeof(ControlValuePropertyAttribute)];
// If no property name is specified, use the ControlValuePropertyAttribute to determine which property to use.
if (propertyName.Length == 0) {
if ((controlValueProp != null) && (!String.IsNullOrEmpty(controlValueProp.Name))) {
propertyName = controlValueProp.Name;
}
else {
throw new InvalidOperationException(SR.GetString(SR.ControlParameter_PropertyNameNotSpecified, controlID, Name));
}
}
// Get the value of the property
object value = DataBinder.Eval(foundControl, propertyName);
// Convert the value to null if this is the default property and the value is the property's default value
if (controlValueProp != null &&
String.Equals(controlValueProp.Name, propertyName, StringComparison.OrdinalIgnoreCase) &&
controlValueProp.DefaultValue != null &&
controlValueProp.DefaultValue.Equals(value)) {
return null;
}
return value;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RootBrowserWindowProxy.cs
- SecurityBindingElementImporter.cs
- XmlHierarchicalEnumerable.cs
- UrlMappingsSection.cs
- PropertyMapper.cs
- ThemeDictionaryExtension.cs
- ScopelessEnumAttribute.cs
- cookie.cs
- DeploymentSectionCache.cs
- InitializerFacet.cs
- AgileSafeNativeMemoryHandle.cs
- HMACSHA512.cs
- MenuItem.cs
- CompilerResults.cs
- WindowsClientElement.cs
- ToolboxComponentsCreatedEventArgs.cs
- ApplicationServiceManager.cs
- SafeNativeMethods.cs
- DocumentPageTextView.cs
- _FtpDataStream.cs
- DataGridViewSelectedRowCollection.cs
- ConstraintManager.cs
- PreviewKeyDownEventArgs.cs
- SafeCertificateContext.cs
- NativeMethods.cs
- QuadraticBezierSegment.cs
- VisualState.cs
- LogFlushAsyncResult.cs
- TableParagraph.cs
- TcpStreams.cs
- TextServicesHost.cs
- figurelengthconverter.cs
- FileStream.cs
- RotationValidation.cs
- SQLRoleProvider.cs
- ProfileBuildProvider.cs
- TypeBuilder.cs
- ProxyAttribute.cs
- FieldBuilder.cs
- MemberRelationshipService.cs
- x509utils.cs
- BrowserCapabilitiesFactory.cs
- StdRegProviderWrapper.cs
- hebrewshape.cs
- WebControlAdapter.cs
- MimeBasePart.cs
- ExtendedPropertyCollection.cs
- ADRole.cs
- SqlReorderer.cs
- PageSettings.cs
- PopupControlService.cs
- Subtree.cs
- NamespaceList.cs
- TextTreeRootNode.cs
- TextContainer.cs
- PartitionedDataSource.cs
- SelectionListComponentEditor.cs
- FilterElement.cs
- EntityDataReader.cs
- FilterException.cs
- XmlNamedNodeMap.cs
- MatrixConverter.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- dataSvcMapFileLoader.cs
- SqlMetaData.cs
- SqlWriter.cs
- FontSource.cs
- NativeMethods.cs
- XmlProcessingInstruction.cs
- RtfToXamlReader.cs
- HtmlTableCellCollection.cs
- ClientEventManager.cs
- SHA384Managed.cs
- BufferedStream2.cs
- CustomErrorCollection.cs
- SmiMetaDataProperty.cs
- WorkflowRuntimeService.cs
- TimeSpanSecondsConverter.cs
- ServiceRoute.cs
- OracleParameter.cs
- FileInfo.cs
- DataGridViewCellValidatingEventArgs.cs
- ObfuscationAttribute.cs
- HandlerMappingMemo.cs
- StructuredProperty.cs
- WarningException.cs
- SystemTcpConnection.cs
- ScopedKnownTypes.cs
- CodeValidator.cs
- NativeMethods.cs
- TextTrailingCharacterEllipsis.cs
- BitmapCodecInfo.cs
- DataGridBoolColumn.cs
- BitStream.cs
- UniformGrid.cs
- AccessDataSource.cs
- DaylightTime.cs
- RootDesignerSerializerAttribute.cs
- MetadataArtifactLoaderResource.cs
- CollectionViewProxy.cs