coComment for CS 2007 updated
Every day you can learn something new. Today it was Scott who taught me ControlAdapter
s after he read my post about coComment with CommunityServer 2007. You know, ControlAdapter
s 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
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.
Leave a Comment
Your email address will not be published. Required fields are marked *