Saturday, 3 October 2015

Example to force form control to failed in Kentico BizForm - Code Behind

Leave a Comment
This is a example to manually force stop the bizform to continue processing save data and show error message to the Field Form Control.

Note this is just 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;  
     base.OnLoad(e);  
   }  



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  
         fieldFormController.Focus();  
         //show error message  
         viewBiz.DisplayErrorLabel("<field name>", "Field must have character \"*\"");  
       }       
     }  
   }  





By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.