Sitecore 8: Get Sublayout item when .ascx file is shared

I have two sublayouts: Grid-1-2 and Grid-2-1.

The two sublayouts are sharing a single ASCX file (not a good sitecore practice but i need it this way).

The problem is that in the ASCX codebehind, i want to see if the current selected grid is Grid-1-2 or Grid-2-1 ?!

I have tried using both Datasource and RenderingId techniques but to no effect.


I was wondering if i can get the "Parameters" field from "Data" section of the sublayout. This would do the trick.

All suggestions are welcomed. Please Help !!


Can you try with :


Also other option is:

LayoutDefinition layoutDef = LayoutDefinition.Parse(Sitecore.Context.Item.Fields["__renderings"].Value);
string deviceId = Sitecore.Context.Device.ID.ToString();
DeviceDefinition curDeviceDef = layoutDef.GetDevice(deviceId);
RenderingDefinition renderingDef = curDeviceDef.GetRendering(Sitecore.Context.Database.Items["/sitecore/Layout/SubLayouts/MySublayout"].ID.ToString());
int controlIndex = curDeviceDef.GetIndex(renderingDef.UniqueId);
Control MyDotNetControl = Sitecore.Context.Page.Renderings[controlIndex].GetControl();

We have the following methods on a base class that all our sublayout controls inherit from... you could just pass in a parameter on each sublayout to identify it and retrieve it using the GetParameter method.. e.g. name="Grid-1-2" etc

    public string GetParameter(string key, string defaultValue = null)
        Sublayout s = this.SitecoreSublayout;
        if (s != null)
            if (!String.IsNullOrWhiteSpace(s.Parameters))
                NameValueCollection pars = HttpUtility.ParseQueryString(s.Parameters);
                if (pars != null)
                    return pars[key];
        return defaultValue;

    protected Sublayout SitecoreSublayout
            Sublayout parent = this.Parent as Sublayout;
            return parent;

Need Your Help

Using jQuery, how can I get an image to open full screen to the browser's height and width?

javascript jquery-ui jquery css

I'd like to create a jQuery function that accepts an image url, and when executed, displays the image full screen matching the height and width of the current page.

Java Sudoku Solution Verifier

java arrays matrix methods boolean

I am currently attempting to create a Java program that reads 81 integers (1-9) into an 9 X 9 matrix, and then tests to see if that matrix is a solution to a Sudoku puzzle. The parameters for a Sud...