Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

How do you get dynamic content to execute when you're manipulating the XHTML property via an adapter?

Vote:
 

I have a control adapter that does some manipulation on EPiServer properties.  It's declared like this:

public class EPiServerContentFilter : PropertyDataControlAdapter

I override the Render method, and do some stuff, like this:

 

  protected override void Render(HtmlTextWriter writer)
        {
            if (Page is BancorpPage)
            {
                (Control as PropertyXhtmlStringControl).SetupControl();
                string html = base.ToWebString();
                ProcessSparkTemplate(ref html);
                ProcessTokenReplacement(ref html);
                writer.Write(html)

 

protected override void Render(HtmlTextWriter writer)
{
string html = base.ToWebString();
html = html.Replace("foo", "bar");
writer.Write(html);
}
    

This works fine, with one exception: dynamic content does not execute.

When I just call this --

base.Render()
    

-- it works fine.

I had this same problem when extending the Property control.  I posted about that, but then figured out that I needed to do was call "EnsurePropertyControlsCreated()" which is a method on the base Property class.

However, I can't get at this method inside the adapter.  The adapter as a "Control" property and a "PropertyDataControl" property, neither of which can be cast into "Property."

Ted Nyberg had a good post about manually parsing a control with dynamic content.  The trick to that seemed to be calling "SetupControl" on the PropertyLongString class.  I tried it, but it still didn't work.

So, how do you get dynamic content to execute when you're manipulating the XHTML property via an adapter?

#42957
Sep 07, 2010 17:05
Vote:
 

maybe its just me again, but can't you

protected override void Render(HtmlTextWriter writer)

{

TextWriter myTextWriter = new StringWriter();
HtmlTextWriter myWriter = new HtmlTextWriter(myTextWriter);
base.Render( myWriter);
string html =myWriter.ToString();
html = html.Replace("foo", "bar"); 
writer.Write(html); 
}

#42960
Sep 07, 2010 22:03
Vote:
 

I'll try this tomorrow (when I'm at the client's site again), but I suspect that I'm going to get double output.  "base.Render" and "writer.Write" are both going to output to the response stream.

#43013
Sep 08, 2010 22:17
Vote:
 

The content gets added to the response stream later. The content that is building up is the writer part in Render(HtmlTextWriter writer)

Since we add to another writer, and only add once to the writer its ok :)

#43018
Sep 09, 2010 9:09
Vote:
 

You need to attach a StringBuilder to the StringWriter and string html = stringBuilder.ToString(), otherwise the output will be pretty boring.. :)

And this works for us btw, when overriding OnRender in a UserControl or ASPX.

#43019
Edited, Sep 09, 2010 9:23
Vote:
 

Anders -- you had it (almost, see below).

The thing I missed in your code is that you're creating a "local" HtmlTextWriter, rendering to that, then grabbing the HTML out of it.

The only change is what I think Erik was hinting at above: myWriter.ToString() just returns the class name.  I did this:

myWriter.InnerWriter.ToString()
    

This gave me the underlying HTML.

#43207
Edited, Sep 15, 2010 15:55
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.