Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / UI / WebControls / HiddenField.cs / 4 / HiddenField.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System.ComponentModel;
using System.Security.Permissions;
using System.Collections.Specialized;
///
/// Inserts a hidden field into the web form.
///
[
ControlValueProperty("Value"),
DefaultEvent("ValueChanged"),
DefaultProperty("Value"),
Designer("System.Web.UI.Design.WebControls.HiddenFieldDesigner, " + AssemblyRef.SystemDesign),
ParseChildren(true),
PersistChildren(false),
NonVisualControl(),
SupportsEventValidation,
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class HiddenField : Control, IPostBackDataHandler {
private static readonly object EventValueChanged = new object();
[
DefaultValue(false),
EditorBrowsable(EditorBrowsableState.Never),
]
public override bool EnableTheming {
get {
return false;
}
set {
throw new NotSupportedException(SR.GetString(SR.NoThemingSupport, this.GetType().Name));
}
}
[
DefaultValue(""),
EditorBrowsable(EditorBrowsableState.Never),
]
public override string SkinID {
get {
return String.Empty;
}
set {
throw new NotSupportedException(SR.GetString(SR.NoThemingSupport, this.GetType().Name));
}
}
///
/// Gets or sets the value of the hidden field.
///
[
Bindable(true),
WebCategory("Behavior"),
DefaultValue(""),
WebSysDescription(SR.HiddenField_Value)
]
public virtual string Value {
get {
string s = (string)ViewState["Value"];
return (s != null) ? s : String.Empty;
}
set {
ViewState["Value"] = value;
}
}
///
/// Raised when the value of the hidden field is changed on the client.
///
[
WebCategory("Action"),
WebSysDescription(SR.HiddenField_OnValueChanged)
]
public event EventHandler ValueChanged {
add {
Events.AddHandler(EventValueChanged, value);
}
remove {
Events.RemoveHandler(EventValueChanged, value);
}
}
protected override ControlCollection CreateControlCollection() {
return new EmptyControlCollection(this);
}
[
EditorBrowsable(EditorBrowsableState.Never),
]
public override void Focus() {
throw new NotSupportedException(SR.GetString(SR.NoFocusSupport, this.GetType().Name));
}
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
ValidateEvent(UniqueID);
string current = Value;
string postData = postCollection[postDataKey];
if (!current.Equals(postData, StringComparison.Ordinal)) {
Value = postData;
return true;
}
return false;
}
protected internal override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
if (SaveValueViewState == false) {
ViewState.SetItemDirty("Value", false);
}
}
protected virtual void OnValueChanged(EventArgs e) {
EventHandler handler = (EventHandler)Events[EventValueChanged];
if (handler != null) {
handler(this, e);
}
}
protected virtual void RaisePostDataChangedEvent() {
OnValueChanged(EventArgs.Empty);
}
protected internal override void Render(HtmlTextWriter writer) {
string uniqueID = UniqueID;
// Make sure we are in a form tag with runat=server.
if (Page != null) {
Page.VerifyRenderingInServerForm(this);
Page.ClientScript.RegisterForEventValidation(uniqueID);
}
writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
if (uniqueID != null) {
writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
}
if (ID != null) {
writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
}
string s;
s = Value;
if (s.Length > 0) {
writer.AddAttribute(HtmlTextWriterAttribute.Value, s);
}
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
}
///
/// Determines whether the Value must be stored in view state, to
/// optimize the size of the saved state.
///
private bool SaveValueViewState {
get {
// Must be saved when
// 1. There is a registered event handler for EventValueChanged
// 2. Control is not visible, because the browser's post data will not include this control
// 3. The instance is a derived instance, which might be overriding the OnValueChanged method
if ((Events[EventValueChanged] != null) ||
(Visible == false) ||
(this.GetType() != typeof(HiddenField))) {
return true;
}
return false;
}
}
#region Implementation of IPostBackDataHandler
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
return LoadPostData(postDataKey, postCollection);
}
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System.ComponentModel;
using System.Security.Permissions;
using System.Collections.Specialized;
///
/// Inserts a hidden field into the web form.
///
[
ControlValueProperty("Value"),
DefaultEvent("ValueChanged"),
DefaultProperty("Value"),
Designer("System.Web.UI.Design.WebControls.HiddenFieldDesigner, " + AssemblyRef.SystemDesign),
ParseChildren(true),
PersistChildren(false),
NonVisualControl(),
SupportsEventValidation,
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class HiddenField : Control, IPostBackDataHandler {
private static readonly object EventValueChanged = new object();
[
DefaultValue(false),
EditorBrowsable(EditorBrowsableState.Never),
]
public override bool EnableTheming {
get {
return false;
}
set {
throw new NotSupportedException(SR.GetString(SR.NoThemingSupport, this.GetType().Name));
}
}
[
DefaultValue(""),
EditorBrowsable(EditorBrowsableState.Never),
]
public override string SkinID {
get {
return String.Empty;
}
set {
throw new NotSupportedException(SR.GetString(SR.NoThemingSupport, this.GetType().Name));
}
}
///
/// Gets or sets the value of the hidden field.
///
[
Bindable(true),
WebCategory("Behavior"),
DefaultValue(""),
WebSysDescription(SR.HiddenField_Value)
]
public virtual string Value {
get {
string s = (string)ViewState["Value"];
return (s != null) ? s : String.Empty;
}
set {
ViewState["Value"] = value;
}
}
///
/// Raised when the value of the hidden field is changed on the client.
///
[
WebCategory("Action"),
WebSysDescription(SR.HiddenField_OnValueChanged)
]
public event EventHandler ValueChanged {
add {
Events.AddHandler(EventValueChanged, value);
}
remove {
Events.RemoveHandler(EventValueChanged, value);
}
}
protected override ControlCollection CreateControlCollection() {
return new EmptyControlCollection(this);
}
[
EditorBrowsable(EditorBrowsableState.Never),
]
public override void Focus() {
throw new NotSupportedException(SR.GetString(SR.NoFocusSupport, this.GetType().Name));
}
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
ValidateEvent(UniqueID);
string current = Value;
string postData = postCollection[postDataKey];
if (!current.Equals(postData, StringComparison.Ordinal)) {
Value = postData;
return true;
}
return false;
}
protected internal override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
if (SaveValueViewState == false) {
ViewState.SetItemDirty("Value", false);
}
}
protected virtual void OnValueChanged(EventArgs e) {
EventHandler handler = (EventHandler)Events[EventValueChanged];
if (handler != null) {
handler(this, e);
}
}
protected virtual void RaisePostDataChangedEvent() {
OnValueChanged(EventArgs.Empty);
}
protected internal override void Render(HtmlTextWriter writer) {
string uniqueID = UniqueID;
// Make sure we are in a form tag with runat=server.
if (Page != null) {
Page.VerifyRenderingInServerForm(this);
Page.ClientScript.RegisterForEventValidation(uniqueID);
}
writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
if (uniqueID != null) {
writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
}
if (ID != null) {
writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
}
string s;
s = Value;
if (s.Length > 0) {
writer.AddAttribute(HtmlTextWriterAttribute.Value, s);
}
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
}
///
/// Determines whether the Value must be stored in view state, to
/// optimize the size of the saved state.
///
private bool SaveValueViewState {
get {
// Must be saved when
// 1. There is a registered event handler for EventValueChanged
// 2. Control is not visible, because the browser's post data will not include this control
// 3. The instance is a derived instance, which might be overriding the OnValueChanged method
if ((Events[EventValueChanged] != null) ||
(Visible == false) ||
(this.GetType() != typeof(HiddenField))) {
return true;
}
return false;
}
}
#region Implementation of IPostBackDataHandler
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
return LoadPostData(postDataKey, postCollection);
}
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
#endregion
}
}
// 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
- SqlConnectionPoolProviderInfo.cs
- DelegatedStream.cs
- SizeLimitedCache.cs
- PrivilegedConfigurationManager.cs
- NumberAction.cs
- AdapterUtil.cs
- ColumnWidthChangingEvent.cs
- DataIdProcessor.cs
- ObjectQueryProvider.cs
- FilterQueryOptionExpression.cs
- xml.cs
- SecurityPolicySection.cs
- GeometryModel3D.cs
- DynamicPropertyHolder.cs
- XPathNodeIterator.cs
- CollectionBuilder.cs
- ReadOnlyNameValueCollection.cs
- ObjectRef.cs
- UnitySerializationHolder.cs
- RuntimeConfigLKG.cs
- Parameter.cs
- ScrollPatternIdentifiers.cs
- SHA512.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- DesignerInterfaces.cs
- NavigationWindow.cs
- TextEditorContextMenu.cs
- ThreadInterruptedException.cs
- CodeTypeMember.cs
- Wizard.cs
- PartialArray.cs
- TreeNodeEventArgs.cs
- CommandBindingCollection.cs
- SystemInfo.cs
- ActiveXHost.cs
- FormatConvertedBitmap.cs
- XmlSerializerSection.cs
- EntityDataSource.cs
- ClientCultureInfo.cs
- CanExecuteRoutedEventArgs.cs
- SplitContainer.cs
- SystemUnicastIPAddressInformation.cs
- BackStopAuthenticationModule.cs
- SectionVisual.cs
- Scheduler.cs
- ToolStripProgressBar.cs
- Vector.cs
- LicenseContext.cs
- FullTextLine.cs
- FolderBrowserDialog.cs
- Soap.cs
- SqlReferenceCollection.cs
- InternalUserCancelledException.cs
- BasicExpandProvider.cs
- PersonalizationAdministration.cs
- RoleGroupCollection.cs
- KeyInterop.cs
- XmlWriterSettings.cs
- FlowDocumentPaginator.cs
- BitmapPalettes.cs
- KeyTimeConverter.cs
- __ConsoleStream.cs
- DesignSurfaceServiceContainer.cs
- DeclaredTypeValidator.cs
- ObjectMemberMapping.cs
- DrawToolTipEventArgs.cs
- ConnectionManagementSection.cs
- XmlDataFileEditor.cs
- XmlCountingReader.cs
- MultipartIdentifier.cs
- InputScope.cs
- HMACSHA1.cs
- NamespaceImport.cs
- ContourSegment.cs
- MsmqChannelFactory.cs
- NumericUpDownAcceleration.cs
- XmlCodeExporter.cs
- WebDisplayNameAttribute.cs
- XmlSchemaInclude.cs
- CategoryValueConverter.cs
- ConfigurationStrings.cs
- XmlDeclaration.cs
- _HeaderInfo.cs
- CharConverter.cs
- SqlTypesSchemaImporter.cs
- __Error.cs
- TypedTableHandler.cs
- DataSourceSelectArguments.cs
- UriTemplateLiteralQueryValue.cs
- InstanceLockQueryResult.cs
- MouseGestureConverter.cs
- ClaimTypes.cs
- DetailsViewInsertEventArgs.cs
- AttributedMetaModel.cs
- RuleInfoComparer.cs
- BaseParagraph.cs
- ControlAdapter.cs
- Size.cs
- SharedStatics.cs
- OleDbFactory.cs