Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / UI / WebControls / CustomValidator.cs / 1 / CustomValidator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System.ComponentModel; using System.Web; using System.Security.Permissions; using System.Web.Util; ////// [ DefaultEvent("ServerValidate"), ToolboxData("<{0}:CustomValidator runat=\"server\" ErrorMessage=\"CustomValidator\">{0}:CustomValidator>") ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 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; } } } }Raises the /// ///event for the .
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _BaseOverlappedAsyncResult.cs
- ToolStripItemBehavior.cs
- DataGridViewRowHeaderCell.cs
- TrackBarRenderer.cs
- WebBaseEventKeyComparer.cs
- ButtonChrome.cs
- ResourceExpressionEditorSheet.cs
- EncoderExceptionFallback.cs
- TextWriterTraceListener.cs
- PrintController.cs
- SqlInternalConnection.cs
- StrongNameSignatureInformation.cs
- querybuilder.cs
- MultiPropertyDescriptorGridEntry.cs
- WindowVisualStateTracker.cs
- SqlInternalConnectionTds.cs
- SQLCharsStorage.cs
- EditorPart.cs
- UpdatePanelTrigger.cs
- CellRelation.cs
- TCEAdapterGenerator.cs
- DragStartedEventArgs.cs
- Int32Converter.cs
- CalendarKeyboardHelper.cs
- sqlmetadatafactory.cs
- Int32Rect.cs
- Buffer.cs
- ScriptResourceHandler.cs
- CodeLinePragma.cs
- AdapterSwitches.cs
- TextTreeObjectNode.cs
- DesignDataSource.cs
- DataBoundControl.cs
- XmlDataSourceNodeDescriptor.cs
- TableRowCollection.cs
- DataGridViewCellLinkedList.cs
- WsrmTraceRecord.cs
- XdrBuilder.cs
- LocationReference.cs
- EventTrigger.cs
- LocalizationParserHooks.cs
- ArcSegment.cs
- WorkItem.cs
- DocumentXPathNavigator.cs
- UntypedNullExpression.cs
- DesignDataSource.cs
- _NestedSingleAsyncResult.cs
- DefaultProxySection.cs
- TdsParserSessionPool.cs
- FileLevelControlBuilderAttribute.cs
- NativeMethods.cs
- IHttpResponseInternal.cs
- AsyncSerializedWorker.cs
- CompiledRegexRunnerFactory.cs
- PageEventArgs.cs
- GlyphCache.cs
- EditorPart.cs
- DbParameterCollectionHelper.cs
- Converter.cs
- AnnotationObservableCollection.cs
- SyndicationDeserializer.cs
- ValueProviderWrapper.cs
- CompleteWizardStep.cs
- Utils.cs
- hresults.cs
- TreeNodeCollection.cs
- PointValueSerializer.cs
- ListViewContainer.cs
- GrammarBuilderDictation.cs
- NavigationWindow.cs
- Dictionary.cs
- ToolBarButton.cs
- RotateTransform3D.cs
- FastEncoderWindow.cs
- XmlQuerySequence.cs
- SqlLiftIndependentRowExpressions.cs
- ZipFileInfo.cs
- DataServiceQuery.cs
- ParagraphVisual.cs
- SoapTransportImporter.cs
- TransformCryptoHandle.cs
- ApplyImportsAction.cs
- CommandDesigner.cs
- FileDetails.cs
- ModelProperty.cs
- TextEditorTyping.cs
- DataServiceRequestArgs.cs
- RawStylusInputCustomDataList.cs
- PeerUnsafeNativeCryptMethods.cs
- FormatSettings.cs
- ToggleProviderWrapper.cs
- TrustLevelCollection.cs
- X509ChainElement.cs
- peersecuritysettings.cs
- PointLight.cs
- FileUtil.cs
- DataIdProcessor.cs
- UnlockInstanceAsyncResult.cs
- ArraySegment.cs
- IndicShape.cs