Posts

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(); }

How to convert JSON to C# Class

Today I found one very good tool to convert JSON data to C# class. Please go to this link:  http://json2csharp.com/ You just paste the JSON data, and it will give you the class for each element in the JSON data. Example JSON Data : Note: This example JSON data from TripAdvisor API. { "address_obj": { "street1": "Lot PTB22819 ", "street2": "Jalan Skudai", "city": "Johor Bahru", "state": "Johor", "country": "Malaysia", "postalcode": "80200", "address_string": "Lot PTB22819 Jalan Skudai, Johor Bahru 80200 Malaysia" }, "latitude": "1.485111", "rating": "4.0", "description": "Staying true to our unique no frills concept, we provide you a good night's sleep at outstanding value. Our hotels come with high quality beds, power showers, 24-hour s

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

Compress and decompress stream object in asp.net - GZip

This is a snippet code to provides methods and properties for compressing and decompressing streams using the GZip algorithm. abstract class Stream using System; using System.IO; namespace CompressionMethod { /// <summary> /// Provides a generic view of a sequence of bytes. /// </summary> public abstract class Stream : IDisposable { #region "Properties" /// <summary> /// Gets or sets system stream. /// </summary> public abstract System.IO.Stream SystemStream { get; } /// <summary> /// Gets the length in bytes of the stream. /// </summary> public abstract long Length { get; } /// <summary> /// Gets or sets the position within the current stream. /// </summary> public abstract long Position { get; set; } #endregion #region "Methods"

Compress and decompress stream object in asp.net - Deflate

This is a snippet code to provides methods and properties for compressing and decompressing streams using the Deflate algorithm. abstract class Stream using System; using System.IO; namespace CompressionMethod { /// <summary> /// Provides a generic view of a sequence of bytes. /// </summary> public abstract class Stream : IDisposable { #region "Properties" /// <summary> /// Gets or sets system stream. /// </summary> public abstract System.IO.Stream SystemStream { get; } /// <summary> /// Gets the length in bytes of the stream. /// </summary> public abstract long Length { get; } /// <summary> /// Gets or sets the position within the current stream. /// </summary> public abstract long Position { get; set; } #endregion #region "Methods"

Example code on how to open dialog box when click on the list AdapterView - Android

Image
Today I want to show how to open list items in the dialog box. For this tutorial, you need to have:- Dialog design view_item.xml MyDialogFragment.java class OnClick Event to call dialog. Announcement.java Class AnnouncementHelper Class OnCreateView Method view_item.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="horizontal" android:padding="5dip" android:id="@+id/Announcement" android:transitionGroup="false"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alig

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)