简体   繁体   English

将参数传递给用户控制中的XSLT函数

[英]Passing parameter to XSLT function in user control

In Composite C1, how can I pass a parameter to a C1 function that is rendered within a Webforms user control? 在Composite C1中,如何将参数传递给在Webforms用户控件中呈现的C1函数?

In my case, I want to include the SimpleSearch results in my user control: 就我而言,我想在用户控件中包含SimpleSearch结果:

<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. 如果我为SearchQuery参数放入一个静态值,则将呈现它。

How do I pass the SearchQuery parameter from my CodeBehind so that the function will be rendered correctly? 如何从CodeBehind传递SearchQuery参数,以便正确呈现该函数?

You can do two things 你可以做两件事

  1. Use databinding syntax so the SearchQuery param looks like this instead <f:param name="SearchQuery" value="<%# SearchTerm %>" /> 使用数据绑定语法,以便SearchQuery参数看起来像这样,而不是<f:param name="SearchQuery" value="<%# SearchTerm %>" />

  2. Pass the parameter in CodeBehind. 在CodeBehind中传递参数。 This is usually the easiest and enables you to pass all kinds of complex objects 通常这是最简单的方法,使您可以传递各种复杂的对象

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM