首页 新闻 会员 周边 捐助

求救:一个自定义验证类继承于BaseValidator,在ValidationSummary无法提示

0
悬赏园豆:20 [已关闭问题]

一个自定义验证类继承于BaseValidator,在ValidationSummary无法提示验证消息?请问如何解决?

代码如下:

public class SmartValidator : BaseValidator
    {

        #region .ctor
        public SmartValidator()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        #endregion

        #region Properties
        public string ErrorMessage
        {
            get
            {
                ViewState["ErrorMessage"] = "您输入的身份证号码无效!";
                return (string)ViewState["ErrorMessage"];
            }
            set { ViewState["ErrorMessage"] = value; }
        }
        #endregion

        #region Methods
       

        protected override bool ControlPropertiesValid()
        {
            string controlToValidate = base.ControlToValidate;
            if (controlToValidate.Length > 0)
            {
                base.CheckControlValidationProperty(controlToValidate, "ControlToValidate");
            }
            return true;
        }

        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (base.RenderUplevel)
            {
                string clientID = this.ClientID;
                AddExpandoAttribute(writer, clientID, "evaluationfunction", "CustomValidatorEvaluateIsValid", false);
                AddExpandoAttribute(writer, clientID, "errormessage", this.ErrorMessage, false);
            }
        }

        private void AddExpandoAttribute(HtmlTextWriter writer, string controlId, string attributeName, string attributeValue)
        {
            this.AddExpandoAttribute(writer, controlId, attributeName, attributeValue, true);
        }

        private void AddExpandoAttribute(HtmlTextWriter writer, string controlId, string attributeName, string attributeValue, bool encode)
        {
            AddExpandoAttribute(this, writer, controlId, attributeName, attributeValue, encode);
        }

        private static void AddExpandoAttribute(Control control, HtmlTextWriter writer, string controlId, string attributeName, string attributeValue, bool encode)
        {
            if (writer != null)
            {
                writer.AddAttribute(attributeName, attributeValue, encode);
            }
            else
            {
                Page page = control.Page;
                page.ClientScript.RegisterExpandoAttribute(controlId, attributeName, attributeValue, encode);
            }
        }

       
        protected override bool EvaluateIsValid()
        {
            string inputValue = GetControlValidationValue(this.ControlToValidate);
            return this.OnServerValidate(inputValue);
        }

       protected bool OnServerValidate(string inputValue)
        {

               //....

                return false;

        }

}

Terry Huang的主页 Terry Huang | 初学一级 | 园豆:50
提问于:2009-12-24 05:57
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册