IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
After you Testimonials module: Create the widget designer for the Submit testimonial view, you need to define the necessary properties and methods to retrieve and show the testimonials and the details page, that is, the frontend view.
To create the Testimonials module frontend view:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestimonialsView.ascx.cs" Inherits="SitefinityWebApp.Modules.Testimonials.TestimonialsView" %>
<
asp:MultiView
ID
=
"TestimonialsMultiView"
runat
"server"
ActiveViewIndex
"0"
>
asp:View
"ListView"
h1
>Testimonials</
asp:Repeater
"TestimonialsRepeater"
ItemTemplate
h2
><%# Eval("Name") %></
p
><%# Eval("Summary") %> <
a
href="<%= ResolveUrl(DetailsPageUrl()) %>/<%# Eval("UrlName") %>">Read More »</
></
telerik:RadRating
"RadRating1"
Value='<%# Eval("Rating") %>' Precision="Half" ItemCount="5" ReadOnly="true" />
</
>Have something to add? <
href
"<%= ResolveUrl("
~/Submit") %>">Submit your own testimonial</
"DetailsView"
><
asp:Literal
"Name"
/></
asp:Label
"Text"
/>
"Rating"
Precision
"Item"
ItemCount
"5"
ReadOnly
"true"
em
>Posted: <
"DatePosted"
href="<%= ResolveUrl(Telerik.Sitefinity.Web.SiteMapBase.GetActualCurrentNode().Url) %>">« All Testimonials</
using
SitefinityWebApp.Modules.Testimonials.ControlDesigners;
SitefinityWebApp.Modules.Testimonials.Data;
Telerik.Sitefinity;
Telerik.Sitefinity.Modules.Pages;
Telerik.Sitefinity.Web;
Telerik.Sitefinity.Web.UI.ControlDesign;
[ControlDesigner(
typeof
(TestimonialsViewDesigner)), PropertyEditorTitle(
"Testimonials"
)]
public
static
readonly
string
ViewName =
"TestimonialsView"
;
private
int
_count = 10;
TestimonialsContext context = TestimonialsContext.Get();
Count
{
get
return
_count; }
set
{ _count = value; }
}
enum
ControlMode
List,
Details
ControlMode Mode
TestimonialID == Guid.Empty ? ControlMode.List : ControlMode.Details; }
Guid testimonialID = Guid.Empty;
protected
Guid TestimonialID
if
(testimonialID == Guid.Empty)
var param = Request.RequestContext.RouteData.Values[
"Params"
]
as
[];
(param ==
null
)
Guid.Empty;
var url = param[0];
var testimonial = context.Testimonials.FirstOrDefault(t => t.UrlName == url);
testimonialID = (testimonial ==
) ? Guid.Empty : testimonial.Id;
testimonialID;
void
ShowList()
var testimonials = context.Testimonials.Where(t => t.Published).Take(Count);
TestimonialsRepeater.DataSource = testimonials;
TestimonialsRepeater.DataBind();
TestimonialsMultiView.SetActiveView(ListView);
ShowDetails()
var testimonial = context.Testimonials.Where(t => t.Id == TestimonialID && t.Published).FirstOrDefault();
(testimonial ==
// new default 404 response
RouteHelper.SetUrlParametersResolved();
Name.Text = testimonial.Name;
Text.Text = testimonial.Text;
Rating.Value = testimonial.Rating;
DatePosted.Text = testimonial.DatePosted.ToLongDateString();
TestimonialsMultiView.SetActiveView(DetailsView);
Page.Title =
.Concat(
"Testimonials: "
, testimonial.Name);
Page_Load(
object
sender, EventArgs e)
(IsPostBack)
switch
(Mode)
// List View
case
ControlMode.List:
ShowList();
break
// Details View
ControlMode.Details:
ShowDetails();
Guid DetailsPageID {
; }
DetailsPageUrl()
// check for custom details page
var currentPageUrl = SiteMapBase.GetActualCurrentNode().Url;
(
this
.DetailsPageID == Guid.Empty)
currentPageUrl;
// make sure page exists
var page = App.WorkWith().Pages().Where(p => p.Id ==
.DetailsPageID).Get().FirstOrDefault();
(page ==
// return page url
page.GetFullUrl();
override
OnUnload(EventArgs e)
base
.OnUnload(e);
(context !=
context.Dispose();
In the markup above, you create a ListView to visualize all testimonials. In the TestimonialsView.ascx.cs file, you set the widget designer that the widget uses. You do this by the ControlDesigner attribute.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important