Sitecore Swamp

Dive in the Sitecore Swamp

NAVIGATION - SEARCH

Workaround of data binding for LayoutTempate

Data binding doesn't work inside the LayoutTempate of ListView. The workaround is to utilize the LayoutCreated event to do find-and-assign:

Markup:
<asp:ListView runat="server" OnLayoutCreated="SelectedFiedls_OnLayoutCreated">
    <LayoutTemplate>
        <asp:Literal runat="server" ID="SeletectedFieldsTotal" /> Criteria selected for comparison:</h5>
            <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
    </LayoutTemplate>
    <ItemTemplate>
        ...
    </ItemTemplate>
</asp:ListView>
Code-behind:
protected void SelectedFiedls_OnLayoutCreated(object senderEventArgs e)
{
     var selectedFieldsTotal = ((ListView)sender).FindControl("SeletectedFieldsTotal"as Literal;
     selectedFieldsTotal.Text = SelectedFields.Count().ToString();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------
updated: 2014-01-17 11:49 AM

The method above has issues with ViewState, as the LayoutCreated event is raised when the layout template is created in the ListView control. Obvious, it's too early for ViesState.(see ASP.NET Page LifeCycle Overview)

If using my favorite ControlDataBind event handler:
protected void ControlDataBind(object senderEventArgs e)
{
    ((Control)sender).DataBind();
}
This work can be done like:
<asp:ListView runat="server" OnLayoutCreated="SelectedFiedls_OnLayoutCreated">
    <LayoutTemplate>
        <asp:PlaceHolder runat="server" OnLoad="ControlDataBind">
            <h5><%# SelectedFields.Count() %> Criteria selected for comparison:</h5>    
        </asp:PlaceHolder>
    </LayoutTemplate>
    <ItemTemplate>
        ...
    </ItemTemplate>
</asp:ListView>
Happy coding!!!

Learning Glass.Mapper

  1. Associate mapped class need load the assembly which contains the mapped class.
    public static  class GlassMapperScCustom
    {
    	...
    
    	public static IConfigurationLoader[] GlassLoaders(){			
    			
    		/* USE THIS AREA TO ADD FLUENT CONFIGURATION LOADERS
                * 
                * If you are using Attribute Configuration or automapping/on-demand mapping you don't need to do anything!
                * 
                */
     
            return new IConfigurationLoader[] { new AttributeConfigurationLoader("Choice.Domain.Sitecore") };
    	}
    	...
    }
  2. Auto mapping process the string value, for example, stripping off hyphen with space. To fix this, always specify FieldType:
        [SitecoreType(TemplateId = "{A82DA878-D247-4124-927F-A01C28CD6CAB}"AutoMap = true)]
        public class ProductField
        {
            [SitecoreField(FieldName = "Key"FieldType = SitecoreFieldType.SingleLineText)]
            public virtual string Key { getset; }
        }

Model - Glass.Mapper - Sitecore.Item

The dream tool to map between model class to Sitecore item. Check it out: http://glass.lu/

Step 1, Sitecore Item:

Step 2. Model class
   public class HomePage
    {
        public virtual string Title { get; set; }
        public virtual string MainBody { get; set; }
    }

Step 3. Sublayout Code-behind:
    public partial class HomePageSublayout : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var context = new SitecoreContext();
            Model = context.GetCurrentItem<HomePage>();
        }
        public HomePage Model { get; set; }
    }

Forgot AWS key pair

The first rule is you should not forget your AWS key pair. If you do, like me, there's still a way out, officially:
  1. create a new key pair, and make sure you don't forget it this time
  2. create an image
  3. launch an instance from the image
  4. get windows password
Tried this, but it doesn't work at the last step: the windows password is never ready! After repeated these 3~4 times, i gave up.

Wondering if a fresh instance, can it get the windows password? Yes, it has no problem at all. It seem the problem is only related to the instance created from AWI.

How about detach and re-attach the volume(virtual hard disk) to an new instance? No, it's not feasible in AWS. But the snapshot of the volume is attachable to another instance.

Problem solved!