コード例 #1
0
 /// <summary>
 /// !! MUST be run at the end of the form in markup. !!
 /// Outputs a script tag containing JavaScript code to enable validation on client side.
 /// </summary>
 /// <returns></returns>
 public static string EnableClientValidation(WFModelMetaData WFMetaData, string formId)
 {
     return
         ((new HtmlTag("script", new { type = "text/javascript", language = "javascript" })
     {
         InnerText = WFScriptGenerator.EnableClientValidationScript(WFMetaData, formId)
     }.Render()) +
          WFScriptGenerator.SetupClientValidationScriptHtmlTag().Render());
 }
コード例 #2
0
        protected override void RenderContents(HtmlTextWriter output)
        {
            WFModelMetaData metadata = new WFModelMetaData();

            foreach (DataAnnotationValidatorControl dvc in WebControlUtilities.FindValidators(this.Page))
            {
                WFModelMetaProperty metaprop = WebControlUtilities.GetMetaPropertyFromValidator(this.Page, dvc, metadata);
                metaprop.OverriddenSpanID = dvc.UniqueID;
                if (!String.IsNullOrEmpty(dvc.Text))
                {
                    metaprop.OverriddenErrorMessage = dvc.Text;
                }
                metadata.Properties.Add(metaprop);
            }
            if (Unobtrusive)
            {
                output.Write(WFScriptGenerator.SetupClientUnobtrusiveValidationScriptHtmlTag().Render());
            }
            else
            {
                output.Write(WFScriptGenerator.SetupClientValidationScriptHtmlTag().Render());
                string targetid = "";
                if (String.IsNullOrEmpty(TargetFormClientID))
                {
                    targetid = this.Page.Form.ClientID;
                }
                else
                {
                    targetid = TargetFormClientID;
                }
                output.Write(new HtmlTag("script", new { type = "text/javascript", language = "javascript" })
                {
                    InnerText = WFScriptGenerator.EnableClientValidationScript(metadata, targetid)
                }.Render());
            }
        }