Posts

Showing posts with the label Kentico 8.2

Sample code to check Kentico Xperience Object alternative form.

Kentico Xperience is a powerful CMS that build from asp.net framework. The CMS have an eCommerce solution, Intranet and collaboration, Online Marketing, and Content management that make Kentico Xperience is the most popular CMS nowadays. In Kentico Objects, you can create alternative forms allow you to create different versions of existing forms. The alternative forms can then be used instead of the default form in the system's administration interface or on the live site. This is the snippet for Kentico version 8.xx to check if the page type has an alternative form. Code Behind 1: public bool CheckIfPageTypeHaveAlternativeForm(string EditFormName,string classID) 2: { 3: bool haveForm = false; 4: if (classID != "") 5: { 6: if (CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID).Count > 0) 7: { 8: var DataInfo = CMS.DocumentEngine.CMSD

Kentico 8.xx - Snippet to check if page type have alternative form name

This is the snippet for Kentico version 8.xx to check if page type have alternative form. Code Behind public bool CheckIfPageTypeHaveAlternativeForm(string EditFormName,string classID) { bool haveForm = false; string strEditFormName = ValidationHelper.GetString(EditFormName, ""); if (classID != "") { if (CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID).Count > 0) { var DataInfo = CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID); foreach (CMS.DataEngine.BaseInfo a in DataInfo) { string formName = ValidationHelper.GetString(a.GetValue("FormName"), ""); if (formName.Contains(strEditFormName)) { haveForm = true; break; } }

How to change the properties/method of one web part from within another web part - Kentico

This tutorial is to show how to access the web part properties/method from another web part. This situation basically when you use a repeater name repeater1 and inside repeater transformation you call another User control/web part name repeater2 . Every time you trigger an event on the repeater2 (ie: click, change the value, etc), you want to refresh the repeater1 value. But you cannot access the properties/method directly. Code Behind repeater / repeater1 Override OnInit Event protected override void OnInit(EventArgs e) { RequestStockHelper.Add("repeater2", this); base.OnInit(e); } Code Behind UserControl / repeater2 Called ReloadData() from another webpart. protected void LinkButton1_Click(object sender, EventArgs e) { CMSAbstractWebPart webpart = RequestStockHelper.GetItem("repeater2") as CMSAbstractWebPart; if (webpart != null) { webpart.OnContentLoaded(); }

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; 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 fiel

Add search condition on Kentico smart search API

Below is an example of using the Smart Search API module in Kentico. The API Example inside Kentico not telling this, but I was able to figure out the way.  Kindly have a try on the snippet example  Smart Search Module API - Search With Condition  public void SmartSearchWithCondition(string searchText,string ClassName,string extraCondition) { DocumentSearchCondition docCondition = new DocumentSearchCondition(); docCondition.ClassNames = ClassName; docCondition.Culture = "en-US"; //refer https://docs.kentico.com/display/K82/Smart+search+syntax for the extra condition syntax var condition = new SearchCondition(extraCondition, SearchModeEnum.AllWords, SearchOptionsEnum.FullSearch, docCondition, true); searchText = SearchSyntaxHelper.CombineSearchCondition(searchText, condition); // Get the search index SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("SearchIndex"); if (index != null)

Send email in Kentico 8.xx

This is an example method to send data in Kentico 8.xx Send email method using CMS.EmailEngine; using CMS.EventLog; ::: ::: public static class CustomClass {     public static void SendEmail(string EmailTemplateCode, MacroResolver mcr,string recipients)     {         EmailMessage msg = new CMS.EmailEngine.EmailMessage();         EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate(EmailTemplateCode, SiteContext.CurrentSiteID);                msg.EmailFormat = EmailFormatEnum.Both;         msg.From = eti.TemplateFrom;         msg.Recipients = recipients;         msg.Subject = eti.TemplateSubject;         try         {             EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, msg, eti, mcr, true);         }         catch (Exception ex)         {             EventLogProvider.LogException(ex.Source, "SendEmail", ex);         }     } } How to call method  MacroResolver mcr = new MacroResolver();  mcr.SetNamedSourceData("DomainName", "

Turn off EventLogProvider from store update/delete/insert activity in Kentico

The event log stores information about all events that occur in the system. It is useful to view logged information if unwanted behavior occurs in the system and you want to find out where the problem originates or get additional details. But, some activities you don't want to be stored in the database while you are developing a custom web part. This is the way how to turn off the for a while in your custom code block. Step by Step  Add "using CMS.Base;" Wrap your code block with this using block code. using (CMSActionContext ctx = new CMSActionContext())     {         ctx.LogEvents = false;        //your action here. } So anything code you put under the comment " Your action " will not be recorded in the Event Log table. Have a try.