/// <summary> /// Adds validation error messages to <see cref="FeedbackMessageStore"/>. /// </summary> /// <param name="page"></param> /// <param name="option"></param> public static void AppendValidationErrorsToStore(Page page, FeedbackMessageRenderOption option) { var messageStore = FeedbackMessageStore.Current; if (option.ShowValidationErrors) { ValidatorCollection validators = page.GetValidators(option.ValidationGroup); foreach (FeedbackMessage errorMessage in GetErrorsAsFeedbackMessage(validators)) { messageStore.Add(errorMessage); } } if (option.ShowModelStateErrors) { ModelStateDictionary modelState = page.ModelState; if (!modelState.IsValid) { foreach (FeedbackMessage errorMessage in GetErrorsAsFeedbackMessage(modelState)) { messageStore.Add(errorMessage); } } } }
/// <summary> /// Appends javascript for display messages. /// </summary> /// <param name="control"></param> public static void AppendFeedbackMessageScripts(this Control control, FeedbackMessageRenderOption option = default) { control.Page.PreRenderComplete += (object sender, System.EventArgs e) => { Page page = (Page)sender; FeedbackMessageUtil.AppendValidationErrorsToStore(page, option); page.ClientScript.RegisterStartupScript(page.GetType(), "FeedbackMessages.OnReady", FeedbackMessageSettings.Instance.ScriptBuilder.GetDomReadyScript(), true); }; }
/// <summary> /// Adds validation error messages to <see cref="FeedbackMessageStore"/>. /// </summary> private void AddValidationErrors() { var renderOption = new FeedbackMessageRenderOption() { ShowModelStateErrors = this.ShowModelStateErrors, ShowValidationErrors = this.ShowValidationErrors, ValidationGroup = this.ValidationGroup }; FeedbackMessageUtil.AppendValidationErrorsToStore(Page, renderOption); }
protected override void OnInit(EventArgs e) { base.OnInit(e); var renderOption = new FeedbackMessageRenderOption() { ShowValidationErrors = true }; this.AppendFeedbackMessageScripts(renderOption); //var messageRenderer = new FeedbackMessageRenderer(); //messageRenderer.OuterTagName = "div"; //messageRenderer.InnerTagName = "span"; //messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.INFO, "class", "ui info message"); //messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.SUCCESS, "class", "ui success message"); //messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.WARN, "class", "ui warn message"); //messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.ERROR, "class", "ui error message"); //FeedbackMessagePanel.MessageRenderer = messageRenderer; }
/// <summary> /// Adds validation error messages to <see cref="FeedbackMessageStore"/>. /// </summary> /// <param name="page"></param> /// <param name="option"></param> public static void AppendValidationErrorsToStore(this Page page, FeedbackMessageRenderOption option) { FeedbackMessageUtil.AppendValidationErrorsToStore(page, option); }