Thanks to the response guys,
ApplyTransformation method does seem to be shenanigan ive been waiting for
but lack of docmentation got me frustrated and for the life of me i could not figure out how to fit it into my problem. Further to that, as you say - it doesnt seem to support
ASCX transformationsWriting custom functions will surely reduce the complexity but im not sure if it helps remove un-necessary asp:Placeholders
For example, a sample transformation without custom functions:
<asp:Placeholder runat="server" visible='<%# !String.IsNullOrEmpty(Eval("SomeField").ToString()) && !String.IsNullOrEmpty(Eval("SomeField2").ToString()) && ... %>' >
... some transforation code ...
</asp:Placeholder>
Which will change to below if i use a custom function
<asp:Placeholder runat="server" visible='<%# CustomCode.IfNotEmpty( ["SomeField", "SomeField2", "SomeField3", ...] ) %>' >
... some transforation code ...
</asp:Placeholder>
Yes, alot cleaner but, again, asp:Placeholders doesnt seem to be the right thing for conditional structure.
Heres how ive approaced it recently- Passed all transformations to
local directory- code in ParentTransformation.ascx ( this transformation gets linked from some webpart - repeater etc )
<%@ Register TagPrefix="cms" TagName="Template" Src="ChildTransformation.ascx" %>
... some html structure before ...
<cms:Template id="TemplateControl" runat="server" visible='... some condition similar to asp:Placeholders above ...'></cms:Template>
... some html structure after ...
- code in ChildTransformation.ascx
<p class="item-body"><%# Eval("Title") %></p>
Above approach is alot cleaner and transformation code can be reused which solves one of the problems i mentioned earlier on
transformations hereTaking it a step furtherHeres how im approaching it if there are more than 1 child transformations that needs to be controled by the same condition
<%@ Register TagPrefix="cms" TagName="ChildTransformation" Src="ChildTransformation.ascx" %>
<%@ Register TagPrefix="cms" TagName="ChildTransformationA" Src="ChildTransformation2.ascx" %>
... some html structure before ...
<cms:ChildTransformation id="TemplateControl" runat="server" visible='false'></cms:ChildTransformation>
... some html structure after ...
<cms:ChildTransformationA id="TemplateControl2" runat="server" visible='false'></cms:ChildTransformationA>
<script runat="server">
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
string Title = DataBinder.Eval(this.DataItem, "Title" ).ToString();
if ( Title.Contains("A") )
{
ChildTransformation.Visible = false;
ChildTransformationA.Visible = false;
}
}
</script>
Next Question:While the above approach is butt-loads better than what ive been doing before,
i wonder if showing-hiding cms:ChildTransformation on data binding can be more dried up?
Im struggling to figure out a way to dynamicaly find out all the controls whose id starts with, lets say "ChildTransformation"
- heres an approach that does the similar thing on dataItems but i cant seem to get this work on controls.
Simply put - is there a way to access all the controls on dataBind event ?
<script runat="server">
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
for (int i = 0; i <= 9; i++)
{
FieldValue = DataBinder.Eval(this.DataItem, "FieldName" + i.ToString()).ToString();
}
}
</script>
appreciate your help gus.
Cheers
Varinder