Return to doc.sitecore.com

Valid for Sitecore 6.x
Can I get the DataSource set and Parameters for a sublayout via code-behind? (Sitecore CMS 6)

Click here to view the version of this FAQ entry for Sitecore 5.2.

Click here to view the version of this FAQ entry for Sitecore 5.3

Q: 

Can I get the DataSource set and Parameters for a sublayout via code-behind?

A: 

Set a certain layout and sublayout for an item with Parameters and DataSource:

/upload/sdn5/faq/api/sublayout via code-behind/sublayoutdatasource6.jpg 

To be able to use the parameters, use the following code:

string rawParameters = Attributes[“sc_parameters”];
NameValueCollection parameters = Sitecore.Web.WebUtil.ParseUrlParameters(rawParameters);

Use the following code to get sublayout datasource in the codebehind of the sublayout:

1.  Codebehind

      protected void Page_Load(object sender, EventArgs e)
        {
            
string ds = ((Sitecore.Web.UI.WebControls.Sublayout)this.Parent).DataSource;
        }