public void DisplayError(string message) { this.Validators.Add(new ValidationError(message)); } public void DisplayError(string message, params string[] p) { DisplayError(String.Format(message, p)); } public void DisplayMessage(string message) { this.Validators.Add(new NotificationValidator(message)); }
protected void Page_Load(object sender, EventArgs e) { rptNotification.DataSource = this.Page.Validators; rptNotification.DataBind(); rptNotification.Visible = (this.Page.Validators.Count != 0); for (int idx = (this.Page.Validators.Count - 1); idx >= 0; idx--) { IValidator val = this.Page.Validators[idx]; this.Page.Validators.Remove(val); } }
protected void rptNotification_ItemDataBound(object sender, RepeaterItemEventArgs e) { try { if ((e.Item.ItemType == ListItemType.Item) || ((e.Item.ItemType == ListItemType.AlternatingItem))) { IValidator val = Page.Validators[e.Item.ItemIndex]; Image img = (Image)e.Item.FindControl("imgNotice"); if (img != null) { if (val is NotificationValidator) img.ImageUrl = "~/images/info.png"; if (val is ValidationError) img.ImageUrl = "~/images/error.png"; if (val is ValidationWarning) img.ImageUrl = "~/images/warning.png"; } Label lblInfo = (Label)e.Item.FindControl("lblDetails"); if (lblInfo != null) { lblInfo.Text = val.ErrorMessage; if (val is NotificationValidator) lblInfo.CssClass = "NotificationItem"; if (val is ValidationError) lblInfo.CssClass = "ErrorItem"; if (val is ValidationWarning) lblInfo.CssClass = "WarningItem"; } } } catch (Exception ex) { //TODO: Log the error } } }
Powered by: newtelligence dasBlog 2.3.9074.18820
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, © Copyright 2010
E-mail