November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Hello!
I found a solution that I publish here in case it helps somebody else in the same situation.
I had tried to add a Label to the controls collection with no success. The problem was that I was creating a EPiServer.XForms.WebControls.Label which for some reason couldn't be added. Changing to a System.Web.UI.WebControls.Label worked fine and the error message was displayed on the page. The code looks like this:
public void XForm_BeforeSubmitPostedData(object sender, SaveFormDataEventArgs e) { XFormControl control = (XFormControl)sender; PageBase currentPage = control.Page as PageBase; if (currentPage == null) { return; } //We set the current page that the form has been posted from //This might differ from the actual page that the form property exists on. e.FormData.PageGuid = currentPage.CurrentPage.PageGuid; //Validation of email addresses string emailAddress = e.FormData.GetValue("Email"); string repeatEmailAddress = e.FormData.GetValue("RepeatEmail"); if (emailAddress != null && repeatEmailAddress != null) { if (!emailAddress.Equals(repeatEmailAddress)) { control.Controls.Add(CreateErrorLabel(CurrentBlock.ErrorMessage,"error")); e.CancelSubmit = true; } } }
And the CreateErrorLabel method:
private Label CreateErrorLabel(string labelText, string cssClass) { Label label = new Label(); label.CssClass = cssClass; label.BackColor = Color.White; label.Text = labelText; return label; }
Hello!
How can I show a custom error message in an XForm? I tried creating a Label and adding it to control.Controls collection but it didn't work. Now I've tried to do something like this
but e.ErrorMessage is not displayed anywhere. Having a control to display errors in the markup of the block (not in the form) doesn't make a difference either since the properties are not updated for some reason. It's frustrating. Can anyone help?
Thanks!