Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / 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; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.Raises the /// ///event for the .
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Timeline.cs
- HttpCookiesSection.cs
- WorkflowDefinitionDispenser.cs
- X509KeyIdentifierClauseType.cs
- BitmapCodecInfoInternal.cs
- PixelFormat.cs
- SafeNativeMethods.cs
- DrawingImage.cs
- SynchronizationFilter.cs
- SHA512Managed.cs
- SymmetricAlgorithm.cs
- PageFunction.cs
- XhtmlCssHandler.cs
- XamlReaderConstants.cs
- LineServices.cs
- SizeAnimationBase.cs
- NativeMethods.cs
- DetailsView.cs
- SqlDelegatedTransaction.cs
- ManifestResourceInfo.cs
- Control.cs
- TraceUtils.cs
- QuaternionValueSerializer.cs
- MessageQueuePermissionEntryCollection.cs
- RegexTypeEditor.cs
- ElementNotEnabledException.cs
- ItemCollection.cs
- GetPageCompletedEventArgs.cs
- InputLanguageSource.cs
- SqlErrorCollection.cs
- ObjectParameterCollection.cs
- ValidationErrorCollection.cs
- TextServicesDisplayAttributePropertyRanges.cs
- TemplateBindingExpressionConverter.cs
- SqlDataSourceConfigureFilterForm.cs
- BuildDependencySet.cs
- WizardPanel.cs
- ControlBuilderAttribute.cs
- RepeaterDesigner.cs
- LoggedException.cs
- NegotiateStream.cs
- DataReaderContainer.cs
- UriTemplateLiteralQueryValue.cs
- AlternateView.cs
- CharacterString.cs
- DataServicePagingProviderWrapper.cs
- ComponentCommands.cs
- SelectedPathEditor.cs
- SmiGettersStream.cs
- diagnosticsswitches.cs
- CatalogZone.cs
- EntityException.cs
- NamespaceMapping.cs
- StylusPlugInCollection.cs
- PathTooLongException.cs
- StringValidatorAttribute.cs
- SqlDataSourceCache.cs
- TargetInvocationException.cs
- IsolatedStorageFilePermission.cs
- OpenTypeLayout.cs
- PerformanceCounter.cs
- OperationCanceledException.cs
- CapabilitiesSection.cs
- InheritanceRules.cs
- NumberFormatter.cs
- ResolveNameEventArgs.cs
- KerberosSecurityTokenProvider.cs
- QilFactory.cs
- DesignerActionUIStateChangeEventArgs.cs
- DashStyle.cs
- UIElementCollection.cs
- SyndicationDeserializer.cs
- BaseValidator.cs
- AutoScrollExpandMessageFilter.cs
- SchemaTableColumn.cs
- TextContainerChangedEventArgs.cs
- PropertyTabAttribute.cs
- ApplicationDirectory.cs
- safelinkcollection.cs
- SemanticValue.cs
- SiteMap.cs
- EntityKeyElement.cs
- UdpDiscoveryEndpoint.cs
- FrameworkTemplate.cs
- SQLString.cs
- CredentialSelector.cs
- DuplicateDetector.cs
- MimeMultiPart.cs
- HttpGetClientProtocol.cs
- LambdaCompiler.Statements.cs
- PngBitmapDecoder.cs
- TextCharacters.cs
- listitem.cs
- EntityDataSourceContextCreatingEventArgs.cs
- ObjectDataProvider.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- SchemaRegistration.cs
- Size3DConverter.cs
- XhtmlBasicSelectionListAdapter.cs
- OraclePermissionAttribute.cs