0

In Composite C1, how can I pass a parameter to a C1 function that is rendered within a Webforms user control?

In my case, I want to include the SimpleSearch results in my user control:

<rendering:Function runat="server" id="fnSimpleSearch" >
    <f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Composite.Search.SimplePageSearch.SearchResults">      
        <f:param name="SearchQuery" value="<%= SearchTerm %>" /> 
        <f:param name="CurrentSite" value="False" /> 
        <f:param name="PageSize" value="10" /> 
        <f:param name="ShowSearchForm" value="True" />      
    </f:function> 
</rendering:Function>

This is the CodeBehind:

public string SearchTerm { get; set; }

protected override void OnLoad(EventArgs e)
{
    C1PageRoute.RegisterPathInfoUsage();
    string pathInfo = C1PageRoute.GetPathInfo();
    if(!string.IsNullOrWhiteSpace(pathInfo))
    {
        SearchTerm = pathInfo.Substring(1);
    }

    base.OnLoad(e);
}

If I do it this way, the function will not be rendered in the final page, instead just the markup is rendered. If I put a static value in for the SearchQuery parameter, it is rendered though.

How do I pass the SearchQuery parameter from my CodeBehind so that the function will be rendered correctly?

magnattic
  • 12,638
  • 13
  • 62
  • 115

1 Answers1

1

You can do two things

  1. Use databinding syntax so the SearchQuery param looks like this instead <f:param name="SearchQuery" value="<%# SearchTerm %>" />

  2. Pass the parameter in CodeBehind. This is usually the easiest and enables you to pass all kinds of complex objects

    fnSimpleSearch.Parameters.Add(new Param("SearchQuery", SearchTerm));

Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
  • I tried the Databind syntax already, same result. Will try the Codebehind version. – magnattic Mar 05 '13 at 11:18
  • `fnSimpleSearch` doesn't have a `Parameter` property. Its type is `CompositeC1Contrib.Web.UI.Rendering.Function`. Am I running an old version of this library or what is going on? The only public property I see is `Content`. – magnattic Mar 05 '13 at 11:22
  • i can't answer you if you run an old version of the library, but for sure the Function-class does have a Parameter property https://bitbucket.org/burningice/compositec1contrib/src/57a7151ed25660329030eb639f9daf323607f545/Rendering.MasterPages/Web/UI/F/Function.cs?at=default – Pauli Østerø Mar 05 '13 at 13:53
  • That seems to be another `Function` class than the one I am using (namespace there is `CompositeC1Contrib.Web.UI.F`, mine is `CompositeC1Contrib.Web.UI.Rendering`). Am I maybe using the wrong syntax to add the function to the user control aspx? – magnattic Mar 05 '13 at 14:07
  • its from 2011-11-25 (https://bitbucket.org/burningice/compositec1contrib/commits/2154e106f7519aaac29abcdb3cd82fdc643d6905), so if you're using an older version than that i suppose its time to upgrade. – Pauli Østerø Mar 05 '13 at 14:25
  • Prior to this version, it was the actual xml-markup written inside the rendering:Function tag that got executed. The only possibility to inject dynamic markup, was to create a StringBuilder in codebebind, build up the markup and pass it to rendering:Function. – Pauli Østerø Mar 06 '13 at 10:43
  • I still can't get it to work. I updated and tried your two solutions, but apparently the function is being rendered before the Control OnInit event? What would be the proper way to go about this? – magnattic Mar 07 '13 at 14:48