Sunday, 21 December 2014

Radio Button Inside Update Panel Does Not Postback Always!

Hey Friends - Sitecore Journey is about to complete ONE SUCCESSFUL YEAR of blogging!!!
How about your Sitecore Journey?

Recently while working on last release of project, I came across a situation which made me write to this post. I am sure this will help you in your Journey.

Scenario/Situation:
We were adding ScriptManager at run-time by checking whether any scriptmanger already exists on page or not. The reason is .NET Framework will not allow you multiple scriptmanager on the same page. We were able to manage this perfectly fine.

But one of our pages where we were using radio button inside updatepanel stared behaving differently in above implementation (adding ScriptManager at run-time). Clicking on radio button sometimes postback and sometimes NOT!!!

Solution:
We found that we need to explicitly register our radio button control with ScriptManager for asynchronous post-back as highlighted in below code.


If you are looking for solution to add ScriptManager at runtime by checking whether any scriptmanager exists on any page or not, then you can create placeholder to add scriptmanage at runtime and write code in "Initialize" method of placeholder as explained in below screen.
Thanks to Kiran and Vikram for their help who were involved in this solution!


Merry Christmas and Wish You A Happy New Sitecore Year!!!

Monday, 17 November 2014

Sitecore Interview Questions Book

Today you will be happy to know that Sitecore Journey is going contribute in one more area of Sitecore knowledge sharing.

Now a days it's good to see that Sitecore community is growing and many Sitecore developers are sharing their learning with us.  But still there is one area where we are lacking. There is only one person who has contributed in that area, he is none other than Sitecore Guru - John West.

Yes, I am taking about Sitecore Book. John West has written awesome Sitecore book, it is Sitecore Bible which every Sitecore developer must read.

There was a little thought in my mind when I started blogging about Sitecore.That thought was about writing:
  •  A book which answers all of the questions faced by Sitecore newcomers.
  • A book which can give quick start to new Sitecore developers.

After spending good amount of idle time (e.g. weekends and holidays) on this project, today I am here with first cut of this project - Sitecore Interview Questions book. Although this is very basic book which covers frequently asked Sitecore questions. This first edition contains a collection of 100 Sitecore questions for beginners.

Cover Page:


Back Page:


Thanks to my colleague for designing such nice cover and back pages of this book.



For Sitecore experienced developers, Sitecore Journey has future plan to release second edition of this book having 200 questions and some awesome learning experience included.

Till then stay tuned and have a happy book reading!

[Update - 13th Oct, 2016]

Sitecore Interview Questions book has reached 31K views!

I am continuously getting request for Sitecore Interview Question book download link every other week. I have never thought that it will have such a HUGE 31K views.

After seeing such a huge response and continuous download link request, thought to share full PDF download link in public.

Download Full Book here.

Monday, 10 November 2014

Is Your Sitecore Package NOT Creating Items?

Scenario:
Few days ago, installing Sitecore package on stage server was NOT creating any item at expected location. It surprised me!



Then like other Sitecore developer, we examined the package and at first glance we found it OK.
But after examining package closely, we found that Sitecore package contained different parent item name than expected. So we went back to content editor and found that parent item name was as expected. Then why Sitecore was creating different parent folder name in package?

We were stuck up at this point and solving this puzzle can solve our package issue also.

Findings:
Suddenly we realized that Sitecore has feature called Display Name which empowers you to show different item name in content editor than actual item name. Could it be culprit of this issue?

We kept digging in that direction and found that it was the only culprit of our package installation issue.

Solution:
We went to display name field of our parent item name and found that it was containing text "Why Work Here". We removed that text and it revealed everything. After removing text from display name, we found that original item name was different than "Why Work Here". It was "Why Work Here At" and we saw same name while examining Sitecore package items.


Due to this, Sitecore was creating package for item having name "Why Work Here At" and was trying to install at item name having "Why Work Here" which was NOT existing at destination.

We then recreated package and installed on Stage server. It worked!
This may seem simple issue once you found the reason, but it's good to share.

Have a happy Sitecore Journey!

Saturday, 1 November 2014

Are You Unable To Select User In Sitecore Access Viewer?

My Sitecore Buddies, how is your Sitecore Journey going on?
Ready for today's journey? Let's begin!

If you are developer then FF must be your favorite browser. But if you are NOT able to select user/role under Access Viewer in Sitecore, then this post will help you to fix it.

Scenario:
1) Click Select User in the Access Viewer under Security menu
2) Select Role/User
3) Click OK
4) Neither Role/User is selected or shown in  Recent list


If you are facing such issue, then try to check if any Error under Console option under firebug in your Firefox browser.

If you come across window.top is null error then it's a bug (accepted by Sitecore Support) which can be fixed easily.


Solution:
1. Open the sitecore\shell\Controls\JqueryModalDialogs.html file.
2. Replace the following line:
    dialogRecord.contentIframe.remove();
    With these lines:
     if (top._scDialogs.length == 0 && navigator.userAgent.indexOf("Firefox") != -1) 
     {
          $(dialogRecord.contentIframe.id).remove();
     }
     else 
     {
         dialogRecord.contentIframe.remove();
      }
3. Save the changes and clear your browser cache.


Thank you Mike Chafin for sharing this fix on Sitecore forum. This will help lots of our Sitecore friends and will redirect Sitecore support traffic to Sitecore Journey :)

Keep your Sitecore Journey going on!!!

Tuesday, 28 October 2014

Disable Default Search On Sitecore Media Library: Sitecore 7+

Hey Friends!
What's up? How's your Sitecore? Got chance to work on Sitecore 7+?

If you have started exploring Sitecore 7+ then you may have observed newly added "Search" tab when you select any item from content tree. It is really nice feature in update!

Scenario:
If you got chance to select "Media Library" then you may have observed that by default "Media Library" item search and show all media items. This may result in performance issue when you have loads of media items. I found that many times people are asking about this, so thought to blog it which can help my Sitecore friends!

So If you want to disable this default Media Library search then this post will help you.


Reason:
The reason is "Media Library" has Default Bucket Query set to "text:*&" that shows all media items.

Solution 1:
In order to disable default search on "Media Library" item selection, you can simply remove that "Default Bucket Query" value and make the field value empty.


Now if you go again and select the "Media Library" item, you will see that it will NOT search any media item and will load Media Library item quickly resulting in performance gain.


Solution 2:
If you don't want to remove Default Bucket Query but instead you want to change order of tabs in such a way that Sitecore should show first "Folder" tab and then "Search" tab. So that whenever you select "Media Library" item it will NOT take much time to load the item.

To apply this solution, Go to Configure tab - select Editors option and then Change Order of "Search" item as suggested below.




Have a Happy Siecore Journey!

Tuesday, 21 October 2014

Trick To Add Custom Application Option in Sitecore 7+

Are you struggling to add custom application option in Sitecore Menu?

If you are using Sitecore 6.6 and not able to add application option in Sitecore menu then please visit Jeremy Davis's blog - he has explained the solution very well!

But If you are using Sitecore 7+ then this post will help you.

In Sitecore 6.6, you need to remove .aspx extension from your Application Shortcut item to start displaying in Sitecore menu. But that solution will not work if you are using Sitecore 7+.

In Sitecore 7+ you need to add URL attribute in raw value of Application Field as suggested in below screen-shots.


If you observe any of default application shortcut, you will find this url attribute in Application field raw value.


But when you add your custom application shortcut, no such url attribute is getting added.


Hence you need to add url attribute manually to fix this issue.


 After adding URL attribute, refresh the Content Editor and you will now see your Application option in Sitecore Menu.


Enjoy your Sitecore Journey!

Tuesday, 14 October 2014

Few Sitecore Tips and Tricks


1) How to allow some characters in your Sitecore instance like parentheses?
For example - you want to allow parantheses in Sitecore item name. How can you achieve that?

Solution:
<setting name="ItemNameValidation" value="^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$"/>

<setting name="ItemNameValidation" value="^[\w\*\$][\w\)\(\s\-\$]*(\(\d{1,}\)){0,1}$" />


2) Are you not able to see Sitecore folder or item is in Content Editor tree? But you are able to see it using Sitecore search.

Solution:
Clearing Content Editor cache by IIS Reset will solve above issue.


3) Why does Sitecore remove "-" from page name?

If you have below setting to replace space with "-" then ask client/user NOT to create page with "-" otherwise "-" will be replaced with " " (space) by Sitecore.

<replace mode="on" find=" " replaceWith="-"/>

Solution:
Don't create page with "-" if above setting is ON.

Have a happy Sitecore Journey!

Monday, 13 October 2014

How to increase Sitecore Field height?

This is very simple post but sometimes makes you think how to achieve it. So thought to blog it which may help Sitecore newbies.

If you are looking for increasing Sitecore field height in order to increase visiblity area, then this post will help you for the same. We will see Sitecore Multiline field example to demonstrate this post.

Let's see - below screen shows the default height of Multiline textbox.


Sometimes you want to increase height of Sitecore Multiline textbox in order to get more visibility area. This can be achieved by simply setting "Style" field under "Appearance" section of Sitecore Multiline textbox as suggested below.


You can see now there is more visibility area which will help user to read text with more comfort.


That's all.
Have a Happy Sitecore Journey!

Wednesday, 8 October 2014

Sitecore Informatics: A Newly Launched Module To Track Your Sitecore Website Information At One Place

Howdy my Sitecore mates!

In your day to day work you may have felt sometimes that - it would be really helpful if you can get few frequently required Sitecore information at one place.

The Sitecore information such as:
  • Total number of Sites in your Sitecore instance
  • Total number of Sublayouts in your Sitecore instance along with referrer pages and caching parameters
  • Total number of Templates in your Sitecore instance along with referrer pages
  • Total number of Content Items in your Sitecore instance
  • Total number of Media Items in your Sitecore instance
  • Total number of Users in your Sitecore instance

Now this is possible by newly launched Sitecore Module - Sitecore Informatics
Yes, Sitecore Journey is excited to launch a new Sitecore Module - Sitecore Informatics and we hope that this will benefit many Sitecore people.

You can download it from Sitecore MarketPlace:
https://marketplace.sitecore.net/Modules/Sitecore_Informatics.aspx

Step by step guide to download and install this tool is at:
http://nileshthakkar.github.io/Sitecore-Informatics/

This is how Sitecore Informatics looks like:


  Keep watching below screen-shots to check out what is inside this module:










Hope this tool will make your Sitecore Life Easy!!!

Have a happy Sitecore Journey!

Tuesday, 9 September 2014

Sitecore Module: WeBlog Not Displaying Latest Blog Entries?

Hey Sitecore Techies!
Most of you may be currently enjoying one of the best Sitecore events that every Sitecore developer would like to attend - that is Sitecore Symposium event.

 Hope you are having good learning time. Let's add one more learning today.

Scenario:
If you are using Sitecore Module - WeBlog and if you face a situation where your blog page is NOT showing latest blog posts on live environment, then this post may help you.

Solution:
The solution is simple, you need to rebuild the search index of "WeBlog" and "Web" as shown in below screen capture.


After rebuilding above search indexes, your blog page should now show all expected blog posts.
If you would like to know where WeBlog index is configured?, then you should refer WeBlog.config file under App_Config\Include folder.


Have a happy Sitecore Journey!

Monday, 1 September 2014

How to use one section of site from another site having same layout in sitecore?

Hey Experts - How's your Sitecore journey going on?

Today I would like to share power of device and fallback device in Sitecore with you. So let's go ahead and first see the scenario where this can be helpful.

Scenario/Requirement:
Let's say you have multi sites in your Sitecore instance. One of your sites have a section which needs to be pointed to another site by keeping same layout.

Say for example - You have two sites, site-A and site-B. One of the section of site-B needs to be pointed to site-A. You can simply point to site-A section from site-B easily by giving respective item path of site-A. But challenge over here is - if you point to site-A from site-B then that section will show layout of site-A and you want to have layout of site-B. So how can you achieve this?



Solution:
Below are steps involved to achieve this requirement:
1) Create a new Sitecore device for siteB by pointing fallback device to devices/default


 2) Add "device" attribute for siteB in SiteDefinition.config or web.config whichever you are using.

 
3) Copy controls of section/item of site-A from default device to above newly created device using  presentation -> details option from Sitecore ribbon



Please remember that all the items/pages of siteB does not require to add controls in "siteB" device, you can add controls in "Default" device as well.

You may have question then how will it work as we have mentioned that siteB should use device siteB in SiteDefinition.config file (as mentioned in step-2)?
Yes - you are thinking correctly, but you need to also recall one more point - and that is "Fallback device" which is pointing to "Default" device (as mentioned in step-1).

So flow is like this:
Whenever any Sitecore page of siteB is requested --> It will first look for "siteB" device --> If "siteB" device is found then it will load controls inside that.

Whenever any Sitecore page of siteB is requested --> It will first look for "siteB" device --> If "siteB" device is NOT found --> It will load fallback device controls (which is default device)

Note: In this requirement, we don't have any security constraint of pointing item from one site to another.

Have A Happy Sitecore Journey!!!

Wednesday, 6 August 2014

Create Custom Error Page in Sitecore

Hello Sitecore Techies!
How's your Sitecore Journey going on? Hope you are passing through many milestones in your journey. So let's share this journey with each other.

Scenario:
Have you come across a scenario in your project where you have seen .NET run-time error page (typical yellow .NET error page) and you don't want to show such error page to end user?  If so then you are thinking absolutely right and this post may help you.

So now question is what is simplest way to implement custom error page in Sitecore?

Solution:
We need to keep one thing in our mind to solve this - "error can happen at anytime and anywhere in the project", so where should you can write code to handle error?

There are two places where you can handle this error:
1) Application_Error event in Global.asax
2) Page_Error event in your Layout page

If you have multiple projects under your Sitecore solution and you want to implement custom error page for one of your project then it should be advisable to write code under Page_Error event in Layout page of your project. Every Sitecore project has at-least one layout page (e.g. .aspx page) which will be executed on every page request. So you can write code in this layout file (e.g. .aspx page)

I had exact above scenario so I went with second approach (e.g. Page_Error), if you have only single project and then you can go with fist approach (e.g. Application_Error).

Step-1: Handle Page_Error event in your Sitecore Layout page.
// page-level exception handler
        public void Page_Error(object sender, EventArgs e)
        {
            // retrieve the last exception
            Exception exception = HttpContext.Current.Server.GetLastError();

            // handle only exceptions based on CustomExceptionBase
            // if this exception is based on CustomExceptionBase
            if (exception != null)
            {
                // log and clear the exception
                Sitecore.Diagnostics.Log.Error(exception.ToString(), this);
                HttpContext.Current.Server.ClearError();
                // Pass the error on to the Generic Error page                
                Response.Redirect("/error-page.aspx");
            }
        }


Please note that instead of hard-coding page name as error-page.aspx, you can make it configurable either from web.config or providing general link field at Sitecore Home Root item.

Step-2: Create error-page in Sitecore which will have rich-text field where you can configure your custom error page. Also add any rendering (e.g. Sublayout) on this page which will pull configured error message from rich-text field and render on this error-page.


Output:
No more .NET error page now! User will see your custom user-friendly error page.


Isn't it simple? Yes - it is simple and effective solution. If you are seasoned programmer, you will always show custom error page to user rather than showing .NET error page.
Thanks to Sitecore Guru - John West who has given this idea in his Professional Sitecore Development Book!

So have you implemented your Sitecore custom error page?
Have a happy Sitecore Journey!

Friday, 18 July 2014

How to customize [No Text In Field] message of Sitecore Page Editor?

Hello Sitecore busy bees! How's your Sitecore Journey going on?
Recently one of  the regular Sitecore Journey readers (Varun Shringarpure) raised a small but good to know question. Sitecore Journey was awared about the answer of this question, but was not able to recall. Finally Sitecore Journey found the answer and to keep this answer handy, thought to document it via blog.

Scenario:
User wants to customize the [No Text In Field] message of page editor in Sitecore. Those who don't know where and when this message comes, the answer is - whenever any Sitecore item field is blank and that page is accessed in page editor mode then you will see [No Text In Field] message as mentioned below.



Solution:
Solution is very simple until you find it :)
I think most of you will agree with me that, the best thing about Sitecore is - it's flexibility.
Sitecore is so flexible that you can customize almost everything. This customization can be done either hooking your code or updating settings.

Let's move on and see how can we customize [No Text In Field] message, switch to core database and go to /sitecore/content/Applications/WebEdit/WebEdit Texts item.


Now change Default Text field to customize the message.


Here is the result:


Wednesday, 9 July 2014

Cascading (Auto-Populate) MultiList Field in Sitecore

Hello Sitecore Buddies!
Thank you for accompanying Sitecore Journey. Feeling blessed to have such expert readers!

Sitecore Journey is incomplete without all of you Sitecore expert readers!

Well, Sitecore Journey is here today to share one of the unique requirements. Let's see today's scenario which will illustrate how to create custom field type in Sitecore.

Scenario:
There was a requirement to auto-populate one Sitecore Multilist field based on another Multilist Field in Sitecore - same like cascading dropdownlist of Ajax Toolkit in ASP.NET.

Here's the video which illustrates this requirement:


Solution:
Many of you have already thought about how to achieve this requirement, yes you are correct - you need to create custom field type in Sitecore. So let's create custom Multilist field type control which will populate/bind second Multilist field based on first Multilist's selected values.

Steps:
1) Create separate class library project in your Sitecore solution (if you have already such project then you can of-course use that).

2) Add a CustomMultilist class in this project, inherit CustomMultilist class from MultilistEx.

Below is complete code snippet of CustomMultiList field control:
using Sitecore.Data.Items;
using Sitecore.Shell.Applications.ContentEditor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sitecore.Extensions
{
    public class CustomMultiList : MultilistEx
    {
        protected override void DoRender(System.Web.UI.HtmlTextWriter output)
        {
            this.ExcludeItems();
           base.DoRender(output);
        }

        private void ExcludeItems()
        {   
            Item i = Sitecore.Context.ContentDatabase.GetItem(base.ItemID);

            Sitecore.Data.Fields.MultilistField multilistField =i.Fields["MultilistField1"];
            Item[] selectedItems = multilistField.GetItems();
            StringBuilder sbItemId = new StringBuilder();
            foreach (Item selectedItem in selectedItems)
            {
                sbItemId.Append(selectedItem.Paths.FullPath).Append("|");               
            }

            if (sbItemId.Length > 0)
            {
                this.Source = sbItemId.ToString().Remove(sbItemId.Length - 1, 1);
            }
            
        }
    }
}
3) Compile project and copy Sitecore.Extenstions.DLL in your [Sitecore Website Root]/bin directory.

4) Add below line in web.config of your Sitecore instance.
<source assembly="Sitecore.Extensions" mode="on" namespace="Sitecore.Extensions" prefix="contentExtension"></source> 

5) Create a new fieldtype (e.g. CustomMulitList field) in core database as shown in below image:


6)  Now go to your item template where you want to assign this CustomMultiList field. You should assign this CustomMultiList field to only that field which you want to auto-populate based one another MultiList field.


Enjoy your Sitecore Journey!