The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
Ok, after short break with SiteActivity control, back to the serious stuff. Continuing the “In the mean time series”, we are making headway to the full-fledged products module. In this post I will demonstrate how to enable comments on our products module – module based on Generic Content.
NOTE: This sample has been created and built with Sitefinity 3.5 Service Pack 1, however it will work normally with 3.5 as well. For users running Sitefinity 3.2 the sample should work as well, though you will need to change the references and implementation of RadControls. You can take a look at the first two samples in the developers manual two see how the implementation was done for 3.2.
NOTE: In case you don’t think you need the instructions, you can download the sample code for this project from here and skip the reading.
The process of enabling comments is not much different than the one for enabling categories or tags. Again, we will divide our task in two parts:
Before we proceed, make sure you have at least set up the products module project like it was described in the introductiory article of this series.
On the admin side, we have to enable the CommentsView command and provide the templates for the Comments functionality. Once we are done we will be able to access the CommentsView of Products module which will look like the one at the Figure 1:
Figure 1: CommentsView command on the left and CommentsView control on the right
<dt runat="server" id="commentsDt"><asp:LinkButton ID="commentsLink" Text="<%$Resources:Comments %>" runat="server" /></dt> |
<dd runat="server" id="commentsDd"><asp:Literal runat="server" Text="<%$Resources:CommentsDescription %>"></asp:Literal></dd> |
<%@ Register TagPrefix="cc1" Namespace="Telerik.Cms.Web.UI" Assembly="Telerik.Cms.Web.UI" %> |
<h2> |
<asp:Literal runat="server" Text="<%$Resources:ExploreProducts %>"></asp:Literal></h2> |
<!-- panel which provides User Interface for working with multiple providers in Products module --> |
<div id="providersPanel" runat="server" class="provider SiteMapTools"> |
<cc1:LabelToolTip HelpBoxCssClass="HelpBox" ID="labelHelpBox1" runat="server" LabelMode="true" |
LabelTargetID="providersList" LabelText="<%$Resources:ChangeGroup %>" ToolTipTitle="<%$Resources:Group %>" |
ToolTipText="<%$Resources:AboutGroup %>" AlternateText="<%$Resources:AboutGroup %>"> |
</cc1:LabelToolTip> |
<asp:DropDownList ID="providersList" AutoPostBack="true" runat="server"> |
</asp:DropDownList> |
</div> |
<!-- menu with various commands of CommandPanel --> |
<dl id="expMenu"> |
<dt id="all"> |
<asp:LinkButton ID="contentViewButton" Text="<%$Resources:ProductItems %>" runat="server" /> |
</dt> |
<dd> |
<asp:Literal runat="server" Text="<%$Resources:ControlDescription %>"></asp:Literal> |
</dd> |
<dt id="cat"><asp:LinkButton ID="categoriesView" Text='<%$Resources:Categories %>' runat="server" CausesValidation="false"></asp:LinkButton></dt> |
<dd><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:CategoriesDescription %>"></asp:Literal></dd> |
<dt id="tags"><asp:LinkButton ID="tagsView" Text="<%$Resources:Tags %>" runat="server" CausesValidation="false"></asp:LinkButton></dt> |
<dd><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:TagsDescription %>"></asp:Literal></dd> |
<dt runat="server" id="commentsDt"><asp:LinkButton ID="commentsLink" Text="<%$Resources:Comments %>" runat="server" /></dt> |
<dd runat="server" id="commentsDd"><asp:Literal runat="server" Text="<%$Resources:CommentsDescription %>"></asp:Literal></dd> |
<!-- link is commented out because permissions are not used in SIMPLE IMPLEMENTATION --> |
<!-- |
<dt id="globalPerm"><asp:LinkButton ID="permissionViewButton" Text="<%$Resources:Permissions %>" runat="server" /></dt> |
<dd><asp:Literal ID="Literal3" runat="server" Text="<%$Resources:PermissionsDescription %>"></asp:Literal></dd> |
--> |
</dl> |
public IButtonControl CommentsViewButton |
{ |
get |
{ |
if (commentsViewButton == null) |
commentsViewButton = (IButtonControl) FindRequiredControl<Control>("commentsLink"); |
return commentsViewButton; |
} |
} |
IButtonControl commentsViewButton; |
// set up the behavior of CommentsViewButton |
container.CommentsViewButton.CommandName = "CommentsView"; |
container.CommentsViewButton.Command += button_Command; |
if (container.CommentsViewButton is LinkButton && (ctrlPnl.Mode == Cms.Engine.WebControls.Admin.ControlPanel.Modes.CommentsView || ctrlPnl.Mode == Cms.Engine.WebControls.Admin.ControlPanel.Modes.CommentsEdit)) |
((LinkButton)container.TagsViewButton).CssClass = "sel"; |
protected virtual void button_Command(object sender, CommandEventArgs e) |
{ |
// based on the command name, set the Mode of ControlPanel |
ControlPanel ctrlPnl = ((ControlPanel) base.ControlPanel); |
switch (e.CommandName) |
{ |
case "ContentView": |
ctrlPnl.Mode = Cms.Engine.WebControls.Admin.ControlPanel.Modes.List; |
ctrlPnl.Refresh(); |
break; |
case "CategoriesView": |
ctrlPnl.Mode = Cms.Engine.WebControls.Admin.ControlPanel.Modes.Categories; |
ctrlPnl.Refresh(); |
break; |
case "TagsView": |
ctrlPnl.Mode = Cms.Engine.WebControls.Admin.ControlPanel.Modes.Tags; |
ctrlPnl.Refresh(); |
break; |
case "CommentsView": |
ctrlPnl.Mode = Cms.Engine.WebControls.Admin.ControlPanel.Modes.CommentsView; |
ctrlPnl.Refresh(); |
break; |
} |
// loop through all the buttons, and make the button that sent the command |
// have "sel" css class |
foreach (Control ctrl in container.Controls[0].Controls) |
{ |
if (ctrl is LinkButton) |
{ |
LinkButton button = (LinkButton) ctrl; |
button.CssClass = button.ID == ((LinkButton) sender).ID ? "sel" : ""; |
} |
} |
} |
We are done with the CommandPanel class and you can save and close that file. The last thing on the admin side is to provide our products module with the admin side templates for comments related controls. Like so many times in this series, we’ll turn to the Generic_Content module and copy the templates located there. Copy following files:
~/Sitefinity/Admin/ControlTemplates/Generic_Content/CommentsEdit.ascx
~/Sitefinity/Admin/ControlTemplates/Generic_Content/CommentsList.ascx
~/Sitefinity/Admin/ControlTemplates/Generic_Content/CommentsView.ascx
~/Sitefinity/Admin/ControlTemplates/Generic_Content/App_LocalResources/CommentsEdit.ascx.resx
~/Sitefinity/Admin/ControlTemplates/Generic_Content/App_LocalResources/CommentsList.ascx.resx
~/Sitefinity/Admin/ControlTemplates/Generic_Content/App_LocalResources/CommentsView.ascx
to following folders respectively:
~/Sitefinity/Admin/ControlTemplates/Products
~/Sitefinity/Admin/ControlTemplates/Products
~/Sitefinity/Admin/ControlTemplates/Products
~/Sitefinity/Admin/ControlTemplates/Products/App_LocalResources
~/Sitefinity/Admin/ControlTemplates/Products/App_LocalResources
~/Sitefinity/Admin/ControlTemplates/Products/App_LocalResources
And we’re done with the admin side! Though it takes some “paper” to explain it, actually the process itself takes no more than 5 minutes.
So, we’ve got everything working on the back side, now all we are left with is to add the UI for the visitors to leave and read the comments. Once again, there is a handy control which we are going to steal from the Generic Content module – the name of the control is CommentsList. Let’s start by copying the template for this control from the public templates of the Generic_Content modules to the public templates of our Products module. Copy following files:
~/Sitefinity/ControlTemplates/Generic_Content/CommentsList.ascx
~/Sitefinity/ControlTemplates/Generic_Content/App_LocalResources/CommentsList.ascx.resx
to following folders respectively:
~/Sitefinity/ControlTemplates/Products/
~/Sitefinity/ControlTemplates/Products/App_LocalResources
Now that templates are ready, open following file used to display single product:
~/Sitefinity/ControlTemplates/Products/ContentViewSingleItem.ascx
and add the CommentsList control somewhere in it, by pasting the following lines:
<sfWeb:CommentsList ID="commentsList" runat="server" TemplateUrl="~/Sitefinity/ControlTemplates/Products/CommentsList.ascx"> |
</sfWeb:CommentsList> |
As you can see we have hardcoded the TemplateUrl, but we could also declare it inline, like it is done in Generic_Content or Blog folders (take a look at the detail templates of these modules).
Figure 2: ProductsView control with the CommentsList control – comments enabled on the public side of the module
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.