In my custom aspx page in WSS I am using a DataFormWebPart with an xsl file to render some data. In order to pass values to the xsl I use parameter bindings. Specifically, I need to pass in the server host url like this:
<ParameterBinding
Name="HttpHost"
Location="CAMLVariable"
DefaultValue="http://hardcoded.com" />
This works fine, but the next thing I want to do is to get the host name dynamically. So figuring out how to get that from SharePoint I added the following binding:
<ParameterBinding
Name="HttpHost"
Location="CAMLVariable"
DefaultValue='<%# SPContext.Current.Site.Url.Replace
(SPContext.Current.Site.ServerRelativeUrl, "") %>' />
Now to the problem. The code works as expected if used some other place in the page, but with the above code SharePoint reports:
Web Part Error: The 'ParameterBindings' property of 'WebPartPages:DataFormWebPart' does not allow child objects.
Anyone have a take on this?
Update: I have enabled server side code according to this article
Ok, I found a solution that is not that elegant but it works.
After trying various methods of manipulating the ParameterBindings property without success I thought of how I could get the dynamic value in there using the Location attribute.
The ParameterBinding
Location
attribute refers to where to fetch the value from. Articles like this hints of the "Control()" option. So changing the parameter binding to:
<ParameterBinding
Name="HttpHost"
Location="Control(MyHttpHost, Text)"
DefaultValue="" />
and adding the following code to my page:
<asp:TextBox ID="MyHttpHost" runat="server" Visible="false" />
<script runat="server">
protected void Page_Load()
{
MyHttpHost.Text =
SPContext.Current.Site.Url.Replace(SPContext.Current.Site.ServerRelativeUrl, "");
}
</script>
...actually did the trick!
To get to the parameter values from within the accompanying XSL file I put param elements in the root element. The param name attribute must match that of the ParameterBinding
:
<xsl:stylesheet ...>
...
<xsl:param name="HttpHost"/>
The parameter can then be referenced as any other XSL variable.
Using Server Variables probably makes more sense: http://mdasblog.wordpress.com/2007/10/19/data-view-web-part-parameters-based-on-server-variables/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With