Force form control to failed validation in Kentico BizForm - Code Behind

This is an example to manually force stop the biz form from continue processing save data and show error message to the Field Form Control.

Note this is just an example. You may use this approach to set very complex validation on the Field in BizForm.

OnLoad Method

   protected override void OnLoad(EventArgs e)  
viewBiz.OnAfterSave += viewBiz_OnAfterSave;
viewBiz.OnBeforeSave += viewBiz_OnBeforeSave;

OnBeforeSave Method

  void viewBiz_OnBeforeSave(object sender, EventArgs e)  
//get the field form controller
FormEngineUserControl fieldFormController = viewBiz.FieldControls["<field name>"];
if (fieldFormController != null)
//do custom validation - example fieldFormControl dont have text "*"
if (!fieldFormController.Text.Contains("*"))
//stop biz form from continue processing
viewBiz.StopProcessing = true;
//focus the field / form controller
//show error message
viewBiz.DisplayErrorLabel("<field name>", "Field must have character \"*\"");

Popular posts from this blog

Example to disable save as certain file type in SSRS Report Viewer

Phone book application example - Java

Modal Popup Message Box ASP.NEt C# Example