Thursday, 23 November 2017

Browser back button event handling in javascript

Browser back button event handling

This is tested code for handling browser back button on chrome browser
 

Confirm Form Resubmission Issue on chrome browser

 <script type="text/javascript">      
        jQuery(document).ready(function ($) {
            if(document.URL == "/cathay-general/news.aspx" || document.URL == "/cathay-general/news")
            {
                $.cookie("visits", document.URL);
            }
            else{$.cookie("visits", "");
            }
            if($.cookie("visits") != "" ){               
                if (window.history && window.history.pushState) {
                    $(window).on('popstate', function () {
                        var hashLocation = $.cookie("visits");//location.hash;
                        var hashSplit = hashLocation.split("#!/");
                        var hashName = hashSplit[1];

                        if (hashName !== '') {
                            var hash = window.location.hash;
                            if (hash === '') {                           
                                window.location.href = "/cathay-general/news.aspx";
                            }
                        }
                    });
                    window.history.pushState('forward', null,$.cookie("visits"));//./#forward "/cathay-general/news.aspx"
                }
            }
        });
</script> 

 

Wednesday, 13 September 2017

Call resource strings in transformations

 

Using resource strings in transformations

ASCX Transformation :-

We can use below code

<%# Localize("{$stringKey$}") %>
Text / XML transformations – use localization macro expression string or we can use the GetResourceString method
{$stringKey$}
 

OR 

 {% GetResourceString("stringKey") %}
 

Call resource strings in the Kentico API

Kentico API provide ResHelper.GetString() class
string localizedResult = ResHelper.GetString("stringKey");

 

 

 

 

Wednesday, 6 September 2017

Kentico attachment using API



 // Create an instance of the Tree provider first
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
        // Get the parent node - the API Example folder
        TreeNode parentNode = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/BoardPortal/LakeView-Board-Document", "en-us");    

  if (parentNode != null)
        {

 string filename = filename;
                string file = System.Web.HttpContext.Current.Server.MapPath(@"/LVRedseign/media/Document Repository/" + filename + "");
                //InsertFieldAttachment(parentNode, file);
                AttachmentInfo attachment = null;
                attachment = DocumentHelper.AddAttachment(newNode, "MenuItemTeaserImage", file, tree);
                attachment.AttachmentDocumentID = newNode.DocumentID;
                attachment.AttachmentExtension = ".pdf";
                attachment.AttachmentName = filename;
                attachment.AttachmentMimeType = "application/pdf";
                attachment.Insert();
              
}

Create Document In Kentico using API

private bool CreateDocument()
    {
        // Create an instance of the Tree provider first
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
        // Get the parent node - the API Example folder
        TreeNode parentNode = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/BoardPortal/LakeView-Board-Document", "en-us");

        TreeNode nodeFile = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/Board-Document-pdf", "en-us");

        if (parentNode != null)
        {
            DataTable dt = ReadCsvFile();
          
            foreach (DataRow dr in dt.Rows)
            {
                TreeNode newNode = TreeNode.New("custom.LakeView_Board_Document", tree);//CMS.MenuItem
                //Guid guid = Guid.NewGuid();
                newNode.NodeName = dr["DocumentTitle"].ToString();
                newNode.NodeGUID = Guid.NewGuid();
                //newNode.DocumentName = dr["DocumentTitle"].ToString();
                newNode.NodeAlias = dr["DocumentTitle"].ToString().Replace(" ", "-");             
                //newNode.DocumentCulture = "en-us";             
                newNode.SetValue("Title", dr["DocumentTitle"].ToString());
                newNode.SetValue("Description", dr["Description"].ToString());
                newNode.SetValue("DocumentDate", DateTime.ParseExact(dr["DocumentDate"].ToString(), "dd-MM-yyyy", null));
                newNode.SetValue("IsBoard", Convert.ToBoolean(dr["IsBoard"]));
                newNode.SetValue("IsOperating", Convert.ToBoolean(dr["IsOperating"]));
                newNode.SetValue("DocumentTypes", dr["DocumentType"].ToString());
                newNode.SetValue("DocumentPath", dr["DocumentPath"].ToString());
                newNode.SetValue("CreatedDate", DateTime.ParseExact(dr["CreatedDate"].ToString(), "dd-MM-yyyy", null));
                newNode.SetValue("StartDate", DateTime.ParseExact(dr["StartDate"].ToString(), "dd-MM-yyyy", null));
                newNode.SetValue("EndDate", DateTime.ParseExact(dr["EndDate"].ToString(), "dd-MM-yyyy", null));
                //newNode.DocumentName = dr["DocumentTitle"].ToString();
                newNode.Insert(parentNode.NodeID);//parentNode
                //DocumentHelper.InsertDocument(newNode, parentNode.NodeID, tree);
                //  CMS.WorkflowEngine.DocumentHelper.InsertDocument(node, parent, tree);
                newNode.Publish();              
            }
            return true;
        }
        return false;
    }

Tuesday, 27 June 2017

Item count for Repeater Footer Template


 Below code for count item within footer template :

its working

<%# ((Repeater)Container.NamingContainer).Items.Count %>