This post is an extension of Dave Burke’s wonderful post about making CS comment handling more like .Text. In my case, I wanted to display the comment tool bar (BlogToolBar) at both the top and bottom of the comment feed (similar to lots of forums out there)…it’s all about flexibility right? The second stipulation is that I only wanted to display it in both places if the post actually had replies to it (for aesthetic reasons…if there’s no comments, it looks kinda goofy having the same BlogToolBars sitting right on top of each other). If there are no replies, only display the second BlogToolBar and hide the first one. As I have found it to be so often in CS, the fix was trivial as the necessary components are already in place.
The first change is in Skins/Skin-EntryViewContainer.ascx: You’ll need to add another control declaration for the second BlogToolBar (bear in mind that 2 controls of the same type must have unique ID’s), so something similar to the following:
<Blog:EntryView runat = "Server" ID = "Entry" />
<Blog:BlogPostToolBar runat = "Server" ID = "ToolBar_Top" />
<div id="comments">
<h3><CS:ResourceControl runat="server" ResourceName="Weblog_ContentList_Comments" /></h3>
<Blog:EntryComments runat = "Server" ID = "Comments" />
</div>
<div>
<Blog:BlogPostToolBar runat = "Server" ID = "ToolBar_Bottom" />
</div>
These controls are loaded dynamically at runtime by Blogs.Controls.EntryViewContainer, so you’ll need to add a new control declaration, change the name of the existing BlogToolBar control declaration, and add logic to determine if a post has any replies, like so:
public class EntryViewContainer : WeblogThemedControl
{
private EntryComments comments = null;
private EntryView entry = null;
// jayson.knight — Display BlogToolBar at top and bottom of comment page
// private BlogPostToolBar ToolBar = null;
private BlogPostToolBar ToolBar_Top = null;
private BlogPostToolBar ToolBar_Bottom = null;
...
protected override void AttachChildControls()
{
...
// jayson.knight
// ToolBar = FindControl("ToolBar") as BlogPostToolBar;
ToolBar_Top = FindControl("Toolbar_Top") as BlogPostToolBar;
ToolBar_Bottom = FindControl("ToolBar_Bottom") as BlogPostToolBar;
...
}
void BindData()
{
...
if(CurrentWeblog.EnableComments)
{
comments.DataSource = ps;
comments.DataBind();
}
// jayson.knight
// ToolBar.CurrentPost = we;
// ToolBar.DataBind();
ToolBar_Top.CurrentPost = we;
ToolBar_Bottom.CurrentPost = we;
ToolBar_Top.DataBind();
ToolBar_Bottom.DataBind();
if (we.Replies < 1)
{
ToolBar_Top.Visible = false;
}
...
}
That’s it, you’ll now have the BlogToolBar displayed at both the top and bottom of the comment section when a post has comments on it.
Posted
Apr 13 2005, 05:52 PM
by
Jayson Knight