Monday, December 8, 2008

Sitecore 6: Using Parameters in Web Controls.

In Sitecore v5, using Parameters listed on the sublayout in the presentation details was a lengthy dive into the core UI API.  In Sitecore v6, they've modified it to be simpler.  For instance, if you have a sublayout (*.ascx) that has parameters listed you can now access those Parameters using the following code:

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

However, if you take advantage of using custom WebControls (*.cs) instead of a Sublayout (*.ascx) then that method doesn't work.  Instead you'll want to make use of the Parameters property on the inherited WebControl.

string rawParameters = this.Parameters;
NameValueCollection parameters = WebUtil.ParseUrlParameters(rawParameters);

1 comment:

Anonymous said...

Hi Vapok,
Nice article, thanks! Just wanted to say that the column containing the actual content is really small, so not everything is visible.

Cheers,
Matthijs