Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / WebControls / CustomValidator.cs / 1305376 / CustomValidator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System.ComponentModel; using System.Web; using System.Web.Util; ////// [ DefaultEvent("ServerValidate"), ToolboxData("<{0}:CustomValidator runat=\"server\" ErrorMessage=\"CustomValidator\">{0}:CustomValidator>") ] public class CustomValidator : BaseValidator { private static readonly object EventServerValidate= new object(); ///Allows custom code to perform /// validation on the client and/or server. ////// [ WebCategory("Behavior"), Themeable(false), DefaultValue(""), WebSysDescription(SR.CustomValidator_ClientValidationFunction) ] public string ClientValidationFunction { get { object o = ViewState["ClientValidationFunction"]; return((o == null) ? String.Empty : (string)o); } set { ViewState["ClientValidationFunction"] = value; } } [ WebCategory("Behavior"), Themeable(false), DefaultValue(false), WebSysDescription(SR.CustomValidator_ValidateEmptyText), ] public bool ValidateEmptyText { get { object o = ViewState["ValidateEmptyText"]; return((o == null) ? false : (bool)o); } set { ViewState["ValidateEmptyText"] = value; } } ///Gets and sets the custom client Javascript function used /// for validation. ////// [ WebSysDescription(SR.CustomValidator_ServerValidate) ] public event ServerValidateEventHandler ServerValidate { add { Events.AddHandler(EventServerValidate, value); } remove { Events.RemoveHandler(EventServerValidate, value); } } ///Represents the method that will handle the /// ///event of a /// . /// /// protected override void AddAttributesToRender(HtmlTextWriter writer) { base.AddAttributesToRender(writer); if (RenderUplevel) { string id = ClientID; HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering) ? writer : null; AddExpandoAttribute(expandoAttributeWriter, id, "evaluationfunction", "CustomValidatorEvaluateIsValid", false); if (ClientValidationFunction.Length > 0) { AddExpandoAttribute(expandoAttributeWriter, id, "clientvalidationfunction", ClientValidationFunction); if (ValidateEmptyText) { AddExpandoAttribute(expandoAttributeWriter, id, "validateemptytext", "true", false); } } } } ///Adds the properties of the ///control to the /// output stream for rendering on the client. /// /// protected override bool ControlPropertiesValid() { // Need to override the BaseValidator implementation, because for CustomValidator, it is fine // for the ControlToValidate to be blank. string controlToValidate = ControlToValidate; if (controlToValidate.Length > 0) { // Check that the property points to a valid control. Will throw and exception if not found CheckControlValidationProperty(controlToValidate, "ControlToValidate"); } return true; } ///Checks the properties of the control for valid values. ////// /// EvaluateIsValid method /// protected override bool EvaluateIsValid() { // If no control is specified, we always fire the event. If they have specified a control, we // only fire the event if the input is non-blank. string controlValue = String.Empty; string controlToValidate = ControlToValidate; if (controlToValidate.Length > 0) { controlValue = GetControlValidationValue(controlToValidate); Debug.Assert(controlValue != null, "Should have been caught be property check"); // If the text is empty, we return true. Whitespace is ignored for coordination wiht // RequiredFieldValidator. if ((controlValue == null || controlValue.Trim().Length == 0) && !ValidateEmptyText) { return true; } } return OnServerValidate(controlValue); } ////// protected virtual bool OnServerValidate(string value) { ServerValidateEventHandler handler = (ServerValidateEventHandler)Events[EventServerValidate]; ServerValidateEventArgs args = new ServerValidateEventArgs(value, true); if (handler != null) { handler(this, args); return args.IsValid; } else { return true; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //Raises the /// ///event for the . // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System.ComponentModel; using System.Web; using System.Web.Util; ////// [ DefaultEvent("ServerValidate"), ToolboxData("<{0}:CustomValidator runat=\"server\" ErrorMessage=\"CustomValidator\">{0}:CustomValidator>") ] public class CustomValidator : BaseValidator { private static readonly object EventServerValidate= new object(); ///Allows custom code to perform /// validation on the client and/or server. ////// [ WebCategory("Behavior"), Themeable(false), DefaultValue(""), WebSysDescription(SR.CustomValidator_ClientValidationFunction) ] public string ClientValidationFunction { get { object o = ViewState["ClientValidationFunction"]; return((o == null) ? String.Empty : (string)o); } set { ViewState["ClientValidationFunction"] = value; } } [ WebCategory("Behavior"), Themeable(false), DefaultValue(false), WebSysDescription(SR.CustomValidator_ValidateEmptyText), ] public bool ValidateEmptyText { get { object o = ViewState["ValidateEmptyText"]; return((o == null) ? false : (bool)o); } set { ViewState["ValidateEmptyText"] = value; } } ///Gets and sets the custom client Javascript function used /// for validation. ////// [ WebSysDescription(SR.CustomValidator_ServerValidate) ] public event ServerValidateEventHandler ServerValidate { add { Events.AddHandler(EventServerValidate, value); } remove { Events.RemoveHandler(EventServerValidate, value); } } ///Represents the method that will handle the /// ///event of a /// . /// /// protected override void AddAttributesToRender(HtmlTextWriter writer) { base.AddAttributesToRender(writer); if (RenderUplevel) { string id = ClientID; HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering) ? writer : null; AddExpandoAttribute(expandoAttributeWriter, id, "evaluationfunction", "CustomValidatorEvaluateIsValid", false); if (ClientValidationFunction.Length > 0) { AddExpandoAttribute(expandoAttributeWriter, id, "clientvalidationfunction", ClientValidationFunction); if (ValidateEmptyText) { AddExpandoAttribute(expandoAttributeWriter, id, "validateemptytext", "true", false); } } } } ///Adds the properties of the ///control to the /// output stream for rendering on the client. /// /// protected override bool ControlPropertiesValid() { // Need to override the BaseValidator implementation, because for CustomValidator, it is fine // for the ControlToValidate to be blank. string controlToValidate = ControlToValidate; if (controlToValidate.Length > 0) { // Check that the property points to a valid control. Will throw and exception if not found CheckControlValidationProperty(controlToValidate, "ControlToValidate"); } return true; } ///Checks the properties of the control for valid values. ////// /// EvaluateIsValid method /// protected override bool EvaluateIsValid() { // If no control is specified, we always fire the event. If they have specified a control, we // only fire the event if the input is non-blank. string controlValue = String.Empty; string controlToValidate = ControlToValidate; if (controlToValidate.Length > 0) { controlValue = GetControlValidationValue(controlToValidate); Debug.Assert(controlValue != null, "Should have been caught be property check"); // If the text is empty, we return true. Whitespace is ignored for coordination wiht // RequiredFieldValidator. if ((controlValue == null || controlValue.Trim().Length == 0) && !ValidateEmptyText) { return true; } } return OnServerValidate(controlValue); } ////// protected virtual bool OnServerValidate(string value) { ServerValidateEventHandler handler = (ServerValidateEventHandler)Events[EventServerValidate]; ServerValidateEventArgs args = new ServerValidateEventArgs(value, true); if (handler != null) { handler(this, args); return args.IsValid; } else { return true; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.Raises the /// ///event for the .
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ISO2022Encoding.cs
- DoubleConverter.cs
- EqualityComparer.cs
- CompilerGeneratedAttribute.cs
- GenericEnumConverter.cs
- GroupStyle.cs
- Calendar.cs
- AccessorTable.cs
- TextTreeInsertUndoUnit.cs
- ThemeDirectoryCompiler.cs
- CodeParameterDeclarationExpression.cs
- TextEndOfLine.cs
- WindowsStreamSecurityElement.cs
- Translator.cs
- HttpsChannelFactory.cs
- M3DUtil.cs
- SystemFonts.cs
- ServiceMetadataBehavior.cs
- DataServiceQueryOfT.cs
- XDeferredAxisSource.cs
- StateMachineDesignerPaint.cs
- DependencyPropertyKind.cs
- DataControlFieldCell.cs
- MembershipValidatePasswordEventArgs.cs
- FormViewUpdatedEventArgs.cs
- EFColumnProvider.cs
- DataGridViewAdvancedBorderStyle.cs
- altserialization.cs
- SoapIgnoreAttribute.cs
- SingleStorage.cs
- AlternateViewCollection.cs
- DbException.cs
- EntityType.cs
- FlowDocumentView.cs
- BitmapSizeOptions.cs
- XmlSchemaComplexContentRestriction.cs
- QuaternionRotation3D.cs
- CommandDevice.cs
- ExpressionPrinter.cs
- QuadTree.cs
- HandlerElement.cs
- ProfilePropertyNameValidator.cs
- FormatConvertedBitmap.cs
- DataKey.cs
- InheritablePropertyChangeInfo.cs
- CheckBox.cs
- DrawingImage.cs
- EntityTypeEmitter.cs
- PointHitTestParameters.cs
- Vector3D.cs
- HMACSHA384.cs
- XsltLibrary.cs
- XsdBuildProvider.cs
- WebColorConverter.cs
- XsdValidatingReader.cs
- SequenceDesigner.cs
- _WebProxyDataBuilder.cs
- DateTimeValueSerializerContext.cs
- MailAddress.cs
- ProfileGroupSettingsCollection.cs
- Gdiplus.cs
- ParentQuery.cs
- XsltSettings.cs
- DbConnectionPool.cs
- ParameterCollection.cs
- EntityClientCacheKey.cs
- LayoutUtils.cs
- HwndAppCommandInputProvider.cs
- AstTree.cs
- ActivityAction.cs
- ColorInterpolationModeValidation.cs
- PtsPage.cs
- __TransparentProxy.cs
- ListControlStringCollectionEditor.cs
- FormViewUpdatedEventArgs.cs
- KnownColorTable.cs
- Message.cs
- ViewSimplifier.cs
- PtsHelper.cs
- SoundPlayer.cs
- AnimatedTypeHelpers.cs
- SafeEventLogWriteHandle.cs
- CatchDesigner.xaml.cs
- Events.cs
- ConcatQueryOperator.cs
- XmlEnumAttribute.cs
- StrokeCollectionConverter.cs
- ConfigurationSectionGroup.cs
- DefaultWorkflowSchedulerService.cs
- BuildResultCache.cs
- HMACSHA384.cs
- FlagsAttribute.cs
- SqlMethodCallConverter.cs
- webeventbuffer.cs
- Crc32.cs
- MetadataUtilsSmi.cs
- MexHttpBindingElement.cs
- SessionSwitchEventArgs.cs
- CommonRemoteMemoryBlock.cs
- CurrencyWrapper.cs