tags:

views:

346

answers:

3

I've done this before with a web control, but I can't seem to get it to work with a sublayout. On the Presentation Details for a particular item I'm assigning my Sublayout and then in the additional parameters section specifying the parameter. Here's the code that's in the code-behind for my sublayout. When I run the debugger, RenderPageTitle is just null.

public partial class PageContent : System.Web.UI.UserControl
{
    public String RenderPageTitle { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (RenderPageTitle.ToLower().Equals("false"))
        {
            TitleFieldRenderer.Visible = false;
        }
    }
}
+1  A: 

For anyone interested:

http://alexeyrusakov.com/sitecoreblog/CommentView,guid,a8a51419-4403-42c4-b689-56553d4165cc.aspx

Kyle
Dead link, Godaddy ads.
Jesse Millikan
So you down vote me 5 1/2 months later like I'm somehow responsible that he took down his site? Nice.
Kyle
+1  A: 

please refer http://vapok.blogspot.com/2008/12/sitecore-6-using-parameters-in-web.html

For sitecore6, in the .cs file:

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

or in .ascx file:

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

There may be some better way to do this. It's hard to say.

The parameters to a sublayout are URL encoded (HttpUtility.UrlEncode or similar) and joined together like a querystring, and then placed in the "sc_parameters" attribute of the control.

So, like chiesa said, in a web user control (this is what that blog meant by .ascx file) you can do this:

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

And then you have the parameters as a dictionary of strings. However, these are still encoded, so if they contain anything other than letters and numbers you will probably want to use something like HttpUtility.UrlDecode to fix them.

string color_scheme = HttpUtility.UrlDecode(parameters["ColorScheme"]);
int ash_diffuser_id = // Could have a + sign prepended or something.
  HttpUtility.UrlDecode(Int32.Parse(parameters["AshDiffuserID"]));
Jesse Millikan