Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / UI / HtmlControls / HtmlInputImage.cs / 1 / HtmlInputImage.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* HtmlInputImage.cs
*
* Copyright (c) 2000 Microsoft Corporation
*/
namespace System.Web.UI.HtmlControls {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
///
///
/// The class defines the
/// methods, properties and events for the HtmlInputImage control. This class allows
/// programmatic access to the HTML <input type=
/// image> element on the server.
///
///
[
DefaultEvent("ServerClick"),
SupportsEventValidation,
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class HtmlInputImage : HtmlInputControl,
IPostBackDataHandler, IPostBackEventHandler {
private static readonly object EventServerClick = new object();
private int _x;
private int _y;
/*
* Creates an intrinsic Html INPUT type=image control.
*/
public HtmlInputImage() : base("image") {
}
///
///
/// Gets or sets the image
/// alignment within the form's content flow.
///
///
/*
* Align property.
*/
[
WebCategory("Appearance"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public string Align {
get {
string s = Attributes["align"];
return((s != null) ? s : String.Empty);
}
set {
Attributes["align"] = MapStringAttributeToString(value);
}
}
///
///
/// Gets or sets the alternative text
/// that the browser should display if the image is either unavailable or has not
/// been downloaded yet.
///
///
/*
* Alt property.
*/
[
WebCategory("Appearance"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
Localizable(true)
]
public string Alt {
get {
string s = Attributes["alt"];
return((s != null) ? s : String.Empty);
}
set {
Attributes["alt"] = MapStringAttributeToString(value);
}
}
///
///
/// Gets or sets the
/// border width, in pixels, around the image.
///
///
/*
* Border property, size of border in pixels.
*/
[
WebCategory("Appearance"),
DefaultValue(-1),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public int Border {
get {
string s = Attributes["border"];
return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
}
set {
Attributes["border"] = MapIntegerAttributeToString(value);
}
}
///
///
/// Gets or sets the location of
/// the image file relative to the page on which it is displayed.
///
///
/*
* Src property.
*/
[
WebCategory("Appearance"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
UrlProperty()
]
public string Src {
get {
string s = Attributes["src"];
return((s != null) ? s : String.Empty);
}
set {
Attributes["src"] = MapStringAttributeToString(value);
}
}
///
/// Gets or sets whether pressing the button causes page validation to fire. This defaults to True so that when
/// using validation controls, the validation state of all controls are updated when the button is clicked, both
/// on the client and the server. Setting this to False is useful when defining a cancel or reset button on a page
/// that has validators.
///
[
WebCategory("Behavior"),
DefaultValue(true),
]
public virtual bool CausesValidation {
get {
object b = ViewState["CausesValidation"];
return((b == null) ? true : (bool)b);
}
set {
ViewState["CausesValidation"] = value;
}
}
[
WebCategory("Behavior"),
DefaultValue(""),
WebSysDescription(SR.PostBackControl_ValidationGroup)
]
public virtual string ValidationGroup {
get {
string s = (string)ViewState["ValidationGroup"];
return((s == null) ? String.Empty : s);
}
set {
ViewState["ValidationGroup"] = value;
}
}
///
///
/// Occurs on the server when a user clicks an
/// control.
///
///
[
WebCategory("Action"),
WebSysDescription(SR.HtmlInputImage_OnServerClick)
]
public event ImageClickEventHandler ServerClick {
add {
Events.AddHandler(EventServerClick, value);
}
remove {
Events.RemoveHandler(EventServerClick, value);
}
}
///
///
///
/*
* This method is invoked just prior to rendering.
* Register requires handling postback to determine if image has been clicked.
*/
protected internal override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
if (Page != null) {
if (!Disabled)
Page.RegisterRequiresPostBack(this);
if (CausesValidation)
Page.RegisterPostBackScript();
}
}
///
///
/// Raised on the server when a user clicks an
/// control.
///
///
/*
* Method used to raise the OnServerClick event.
*/
protected virtual void OnServerClick(ImageClickEventArgs e) {
ImageClickEventHandler handler = (ImageClickEventHandler)Events[EventServerClick];
if (handler != null) handler(this, e);
}
///
///
///
/*
* Method of IPostBackEventHandler interface to raise events on post back.
* HtmlInputImage fires an OnServerClick event.
*/
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument) {
RaisePostBackEvent(eventArgument);
}
///
///
///
protected virtual void RaisePostBackEvent(string eventArgument) {
if (CausesValidation) {
Page.Validate(ValidationGroup);
}
OnServerClick(new ImageClickEventArgs(_x, _y));
}
///
///
///
/*
* Method of IPostBackDataHandler interface to process posted data.
* The image control will check to see if the x and y values were posted,
* which indicates that the image was clicked by the user. The image
* control will then register with the Page that it wants to raise an event
* during the event processing phase.
*/
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
return LoadPostData(postDataKey, postCollection);
}
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
string postX = postCollection[RenderedNameAttribute + ".x"];
string postY = postCollection[RenderedNameAttribute + ".y"];
if (postX != null && postY != null &&
postX.Length > 0 && postY.Length > 0) {
ValidateEvent(UniqueID);
_x = Int32.Parse(postX, CultureInfo.InvariantCulture);
_y = Int32.Parse(postY, CultureInfo.InvariantCulture);
Page.RegisterRequiresRaiseEvent(this);
}
return false;
}
///
///
///
/*
* Method of IPostBackDataHandler interface which is invoked whenever posted data
* for a control has changed.
*/
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
///
///
///
protected virtual void RaisePostDataChangedEvent() {
}
/*
* Override to render unique name attribute.
* The name attribute is owned by the framework.
*/
///
///
///
protected override void RenderAttributes(HtmlTextWriter writer) {
PreProcessRelativeReferenceAttribute(writer, "src");
if (Page != null) {
Util.WriteOnClickAttribute(
writer, this, true, false,
(CausesValidation && Page.GetValidators(ValidationGroup).Count > 0),
ValidationGroup);
}
base.RenderAttributes(writer);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* HtmlInputImage.cs
*
* Copyright (c) 2000 Microsoft Corporation
*/
namespace System.Web.UI.HtmlControls {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
///
///
/// The class defines the
/// methods, properties and events for the HtmlInputImage control. This class allows
/// programmatic access to the HTML <input type=
/// image> element on the server.
///
///
[
DefaultEvent("ServerClick"),
SupportsEventValidation,
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class HtmlInputImage : HtmlInputControl,
IPostBackDataHandler, IPostBackEventHandler {
private static readonly object EventServerClick = new object();
private int _x;
private int _y;
/*
* Creates an intrinsic Html INPUT type=image control.
*/
public HtmlInputImage() : base("image") {
}
///
///
/// Gets or sets the image
/// alignment within the form's content flow.
///
///
/*
* Align property.
*/
[
WebCategory("Appearance"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public string Align {
get {
string s = Attributes["align"];
return((s != null) ? s : String.Empty);
}
set {
Attributes["align"] = MapStringAttributeToString(value);
}
}
///
///
/// Gets or sets the alternative text
/// that the browser should display if the image is either unavailable or has not
/// been downloaded yet.
///
///
/*
* Alt property.
*/
[
WebCategory("Appearance"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
Localizable(true)
]
public string Alt {
get {
string s = Attributes["alt"];
return((s != null) ? s : String.Empty);
}
set {
Attributes["alt"] = MapStringAttributeToString(value);
}
}
///
///
/// Gets or sets the
/// border width, in pixels, around the image.
///
///
/*
* Border property, size of border in pixels.
*/
[
WebCategory("Appearance"),
DefaultValue(-1),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public int Border {
get {
string s = Attributes["border"];
return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
}
set {
Attributes["border"] = MapIntegerAttributeToString(value);
}
}
///
///
/// Gets or sets the location of
/// the image file relative to the page on which it is displayed.
///
///
/*
* Src property.
*/
[
WebCategory("Appearance"),
DefaultValue(""),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
UrlProperty()
]
public string Src {
get {
string s = Attributes["src"];
return((s != null) ? s : String.Empty);
}
set {
Attributes["src"] = MapStringAttributeToString(value);
}
}
///
/// Gets or sets whether pressing the button causes page validation to fire. This defaults to True so that when
/// using validation controls, the validation state of all controls are updated when the button is clicked, both
/// on the client and the server. Setting this to False is useful when defining a cancel or reset button on a page
/// that has validators.
///
[
WebCategory("Behavior"),
DefaultValue(true),
]
public virtual bool CausesValidation {
get {
object b = ViewState["CausesValidation"];
return((b == null) ? true : (bool)b);
}
set {
ViewState["CausesValidation"] = value;
}
}
[
WebCategory("Behavior"),
DefaultValue(""),
WebSysDescription(SR.PostBackControl_ValidationGroup)
]
public virtual string ValidationGroup {
get {
string s = (string)ViewState["ValidationGroup"];
return((s == null) ? String.Empty : s);
}
set {
ViewState["ValidationGroup"] = value;
}
}
///
///
/// Occurs on the server when a user clicks an
/// control.
///
///
[
WebCategory("Action"),
WebSysDescription(SR.HtmlInputImage_OnServerClick)
]
public event ImageClickEventHandler ServerClick {
add {
Events.AddHandler(EventServerClick, value);
}
remove {
Events.RemoveHandler(EventServerClick, value);
}
}
///
///
///
/*
* This method is invoked just prior to rendering.
* Register requires handling postback to determine if image has been clicked.
*/
protected internal override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
if (Page != null) {
if (!Disabled)
Page.RegisterRequiresPostBack(this);
if (CausesValidation)
Page.RegisterPostBackScript();
}
}
///
///
/// Raised on the server when a user clicks an
/// control.
///
///
/*
* Method used to raise the OnServerClick event.
*/
protected virtual void OnServerClick(ImageClickEventArgs e) {
ImageClickEventHandler handler = (ImageClickEventHandler)Events[EventServerClick];
if (handler != null) handler(this, e);
}
///
///
///
/*
* Method of IPostBackEventHandler interface to raise events on post back.
* HtmlInputImage fires an OnServerClick event.
*/
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument) {
RaisePostBackEvent(eventArgument);
}
///
///
///
protected virtual void RaisePostBackEvent(string eventArgument) {
if (CausesValidation) {
Page.Validate(ValidationGroup);
}
OnServerClick(new ImageClickEventArgs(_x, _y));
}
///
///
///
/*
* Method of IPostBackDataHandler interface to process posted data.
* The image control will check to see if the x and y values were posted,
* which indicates that the image was clicked by the user. The image
* control will then register with the Page that it wants to raise an event
* during the event processing phase.
*/
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
return LoadPostData(postDataKey, postCollection);
}
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
string postX = postCollection[RenderedNameAttribute + ".x"];
string postY = postCollection[RenderedNameAttribute + ".y"];
if (postX != null && postY != null &&
postX.Length > 0 && postY.Length > 0) {
ValidateEvent(UniqueID);
_x = Int32.Parse(postX, CultureInfo.InvariantCulture);
_y = Int32.Parse(postY, CultureInfo.InvariantCulture);
Page.RegisterRequiresRaiseEvent(this);
}
return false;
}
///
///
///
/*
* Method of IPostBackDataHandler interface which is invoked whenever posted data
* for a control has changed.
*/
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
///
///
///
protected virtual void RaisePostDataChangedEvent() {
}
/*
* Override to render unique name attribute.
* The name attribute is owned by the framework.
*/
///
///
///
protected override void RenderAttributes(HtmlTextWriter writer) {
PreProcessRelativeReferenceAttribute(writer, "src");
if (Page != null) {
Util.WriteOnClickAttribute(
writer, this, true, false,
(CausesValidation && Page.GetValidators(ValidationGroup).Count > 0),
ValidationGroup);
}
base.RenderAttributes(writer);
}
}
}
// 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
- StaticDataManager.cs
- ListSortDescription.cs
- InstanceStore.cs
- WindowAutomationPeer.cs
- FlowNode.cs
- UnsafeNativeMethodsPenimc.cs
- DataControlLinkButton.cs
- DecimalConverter.cs
- WebException.cs
- BuildProvider.cs
- HelpProvider.cs
- OutputCacheModule.cs
- HttpCacheVary.cs
- HorizontalAlignConverter.cs
- AccessorTable.cs
- XmlQueryStaticData.cs
- SignatureGenerator.cs
- LeaseManager.cs
- FtpWebResponse.cs
- RegisteredExpandoAttribute.cs
- TextMessageEncodingBindingElement.cs
- AudioFileOut.cs
- ValidationErrorEventArgs.cs
- EventlogProvider.cs
- SafeCryptContextHandle.cs
- RegionInfo.cs
- CellParaClient.cs
- VectorConverter.cs
- ListViewUpdatedEventArgs.cs
- KnownColorTable.cs
- NativeMethods.cs
- TransactionFlowBindingElementImporter.cs
- XmlCustomFormatter.cs
- XhtmlBasicValidatorAdapter.cs
- DataObjectAttribute.cs
- COAUTHIDENTITY.cs
- WebReferencesBuildProvider.cs
- SwitchLevelAttribute.cs
- XmlSchemaSimpleTypeList.cs
- ManagementObject.cs
- DataChangedEventManager.cs
- VBCodeProvider.cs
- ListenerServiceInstallComponent.cs
- CachedRequestParams.cs
- InstanceLockedException.cs
- DataBindingsDialog.cs
- SamlAssertionKeyIdentifierClause.cs
- ConsumerConnectionPointCollection.cs
- CustomAttributeSerializer.cs
- DivideByZeroException.cs
- InvalidWMPVersionException.cs
- StylusPointCollection.cs
- XmlMapping.cs
- HttpServerVarsCollection.cs
- DataListDesigner.cs
- ObjectSpanRewriter.cs
- ProbeMatchesApril2005.cs
- _SpnDictionary.cs
- AlphaSortedEnumConverter.cs
- UrlMapping.cs
- BaseDataListActionList.cs
- BooleanAnimationUsingKeyFrames.cs
- AutomationPatternInfo.cs
- MarshalDirectiveException.cs
- IndentedWriter.cs
- MailDefinitionBodyFileNameEditor.cs
- ParsedAttributeCollection.cs
- CompilerCollection.cs
- DataGridViewColumnCollectionDialog.cs
- Parameter.cs
- NTAccount.cs
- BevelBitmapEffect.cs
- OracleConnectionFactory.cs
- TablePattern.cs
- StringDictionary.cs
- LogicalExpr.cs
- DocumentPage.cs
- SHA256Managed.cs
- DbConnectionPoolIdentity.cs
- ManipulationLogic.cs
- OracleSqlParser.cs
- ServiceModelSecurityTokenTypes.cs
- PolyQuadraticBezierSegment.cs
- WebPartAddingEventArgs.cs
- QueryInterceptorAttribute.cs
- BaseConfigurationRecord.cs
- Handle.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- BoolExpr.cs
- RSAOAEPKeyExchangeFormatter.cs
- SparseMemoryStream.cs
- HostingEnvironmentSection.cs
- _RequestCacheProtocol.cs
- controlskin.cs
- HttpListenerContext.cs
- Pair.cs
- SortedDictionary.cs
- RowVisual.cs
- HttpValueCollection.cs
- RadioButtonList.cs