Thomas Freudenberg

Confessions of a caffeine addict

coComment for CS 2007 updated

Every day you can learn something new. Today it was Scott who taught me ControlAdapters after he read my post about coComment with CommunityServer 2007. You know, ControlAdapters are not only good for tweaking CSS.

My original solution was a replacement for the WeblogPostCommentForm, i.e. for every blog theme you had to edit its post.aspx, register my new control and replace the original control.

ControlAdapters however give you the power to inject your code into any desired existing control. In a central file you specify which controls you want to customize, and that's it. No editing of any pages or controls is required.

So I took the chance and transformed my custom comment form into a ControlAdapter. In fact, it's as easy as writing a control. Here's the simplified code, just in case you're interested:

public class WeblogPostCommentFormAdapter : ControlAdapter
{
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        WeblogPostCommentForm commentForm = base.Control as WeblogPostCommentForm;
        if (commentForm != null)
        {
            string coCommentScript = GetCoCommentScript(commentForm);
            if (!String.IsNullOrEmpty(coCommentScript))
                CSControlUtility.Instance().RegisterStartupScript(base.Control, 
                    typeof (WeblogPostCommentForm), "cocomment", coCommentScript, false);
        }
    }

    private static string GetCoCommentScript(WeblogPostCommentForm commentForm)
    {
        // just boring stuff which creates the javascript code to make coComment happy
    }
}

Just drop the attached assembly to your ~/bin folder and add following line to the controlAdapters section in ~/App_Browsers/default.browser:

<adapter controlType="CommunityServer.Blogs.Controls.WeblogPostCommentForm"
    adapterType="ThomasFreudenberg.CS2007.WeblogPostCommentFormAdapter, ThomasFreudenberg.CS2007" />

That's all, without further editing of any files1 coComment support is enabled for all blog themes automagically.

1 unless of course if you're already using the assembly I published yesterday; in this case revert all changes done to your post.aspx'

Comments

Dave Burke said:

I knew there had to be a good reason why I didn't mention your original coComment post in today's CS Bytes.  ControlAdapters, eh?  I'm going to have to look into this a bit more.  Thanks for rewriting and for sharing the source.

# April 24, 2007 5:35 PM

Community Server Daily News said:

Community Server MVP Thomas Freudenberg took some very smart advice and converted his coComment add-on

# April 24, 2007 7:41 PM

Dave Burke said:

blog bits Scott Watermasysk's been doing a really good job pointing out the top Community Server news

# April 29, 2007 8:55 AM

Thomas Freudenberg said:

Brendan Tompkins released CAPTCHA for CommunityServer 2007 : I&#39;m happy to announce that CodeBetter

# April 29, 2007 10:12 AM

Dave Burke's Community Server Bits said:

CS MVP Thomas Freudenberg re-releases his CoComment CS2007 Control --thanks to the advice of ScottW--as

# April 29, 2007 10:57 AM

Douglas Rohm said:

If you don't know what CoComment is, be sure to follow the link and find out. It's an easy way for you

# June 11, 2007 9:54 PM

Vekenfofe said:

que nous ferions sans votre idГ©e remarquable  <a href="http://meix-lagor.com">ejaculation precose</a>

# January 13, 2010 12:00 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)