why viewscount posts not working?
Hello,
I created a post, but increasingly people viewing the post, the Views_count continues to zero. why this happens, because it is the trial version or is it that I forgot to do something else.
I also have that doubt, would help me a lot!
Hi Leandro / Renato,
Thank you for contacting us. It seems that this option isn't working. I'm logging it as a bug with ID 106713.
Greetings,Hello!
can you please tell me if it will be addressed with an internal build or have I to wait till SP1?
thanks
Ilaria
Hello Leandro,
Actually there is no implementation for ViewCount. We will try to implement the logic for SP1, but it would be more complicated, since we are talking not for a bug fixing but for entire implementation. Most probably this will be included in one of the internal builds.
Best wishes,
Ivan Dimitrov
the Telerik team
Hello Ivan,
sorry if I get inside this thread... I'm helping Ilaria on the demo project she's working on..... my question is why there's a viewcount member in the class (at the moment public ) if there's no code behind it?
What if we manually increment this? it's possible? Thanks
Hello Paolo,
We left the member for future implementations.
You could try manually to set the value
App.WorkWith().BlogPosts().First().Do(bp1 =>
bp1.ViewsCount = 1;
).SaveChanges();
Best wishes,
Ivan Dimitrov
the Telerik team
I created an aspx page and put this code in Page_Load and it worked, but I need it to be the template full post, how do I put this code in the page that shows the full post?
Thanks
Hi Leandro,
You can drop BlogPostView control on a page and edit its SingleView template from the control designer. You can add server side code inline and subscribe for ItemCreated event of the RadListView. Inside ItemCreated you can access the data item which is the content and set the ViewCount property.
Regards,
Ivan Dimitrov
the Telerik team
Also we have this doubt
how would I add code on the server side and embedded register for this event ItemCreated of RadListView? Could you give me an example?
hello Ivan,
thanks a lot, it works!
i've got an another problem: the counter is increased by code, but only in my custom control. Where can i put the same code for increase the countview when the user open the document from the download list?
Is it possible using a workflow?
Hello,
When you view an item on the public side, the workflow is not called. Generally you should make the same changes in DownloadList control and its templates. You should work with Documents facade instead of using Blogs.
Regards,
Ivan Dimitrov
the Telerik team
Can you please me give me an example about it?
Hello Leandro,
You can create a custom control that is data-bound. Generally, Sitefinity 4.0 public controls are data-bound, and their templates are available through the widget editor.
Since we have not yet moved to the ASP.NET parser for db-stored and embedded templates, you will have to implement a simple control. Here is a very simple, but working sample:
using
System;
using
System.Web.UI;
using
Telerik.Sitefinity.GenericContent.Model;
using
Telerik.Sitefinity.Web;
namespace
Telerik.Sitefinity.Examples
public
class
ContentItemCounter : Control
private
int
? viewsCount =
null
;
protected
override
void
OnDataBinding(EventArgs e)
base
.OnDataBinding(e);
var dbContainer =
this
.GetDataItemContainer();
var contentItem = dbContainer !=
null
? dbContainer.DataItem
as
Content :
null
;
if
(contentItem !=
null
)
App.WorkWith()
.AnyContentItem(contentItem.GetType(), contentItem.Id)
.GetLive()
.Do(c =>
this
.viewsCount = c.ViewsCount;
c.ViewsCount++;
)
.SaveChanges();
protected
override
void
Render(HtmlTextWriter writer)
if
(
this
.viewsCount.HasValue)
writer.Write(
this
.viewsCount.Value);
<%@ Control Language="C#" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sitefinity" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sfEx" Namespace="Telerik.Sitefinity.Examples" Assembly="Telerik.Sitefinity.Examples" %>
<
sitefinity:ResourceLinks
id
=
"resourcesLinks2"
runat
=
"server"
UseEmbeddedThemes
=
"true"
Theme
=
"Default"
>
<
sitefinity:ResourceFile
Name
=
"Telerik.Sitefinity.Resources.Themes.Basic.Styles.icons.css"
Static
=
"true"
/>
</
sitefinity:ResourceLinks
>
<
sf:BrowseAndEditToolbar
ID
=
"browseAndEditToolbar"
runat
=
"server"
Mode
=
"Edit"
></
sf:BrowseAndEditToolbar
>
<
div
id
=
"itemsContainer"
runat
=
"server"
>
<
asp:Repeater
ID
=
"documentsRepeater"
runat
=
"server"
>
<
HeaderTemplate
>
<
ul
class
=
"sfdownloadList sfListMode"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
li
id
=
"docItem"
runat
=
"server"
class
=
"sfdownloadFile"
>
<
sitefinity:SitefinityHyperLink
ID
=
"documentLink"
runat
=
"server"
CssClass
=
"sfdownloadTitle"
target
=
"_blank"
/>
<
sitefinity:SitefinityLabel
id
=
"infoLabel"
runat
=
"server"
WrapperTagName
=
"div"
HideIfNoText
=
"false"
CssClass
=
"sfInfo"
/>
<
sfEx:ContentItemCounter
ID
=
"someID"
runat
=
"server"
/>
</
li
>
</
ItemTemplate
>
<
FooterTemplate
>
</
ul
>
</
FooterTemplate
>
</
asp:Repeater
>
</
div
>
<
sitefinity:Pager
id
=
"pager"
runat
=
"server"
></
sitefinity:Pager
>
Hello!
I try the code you post, but the result of the contentItem is always null, at the end of this instuction:
var contentItem = dbContainer !=
null
? dbContainer.DataItem
as
Content :
null
;
Any suggestion?
edit:
the program return null calling this.GetDataItemContainer() too!
protected
override
void
OnDataBinding(EventArgs e)
base
.OnDataBinding(e);
var dbContainer =
this
.GetDataItemContainer();
var contentItem = dbContainer !=
null
? dbContainer.DataItem
as
Content :
null
;
Hi Leandro,
First, I would like to apologise for the late response.
The most probable reason is that you inserted the item in a context that is not data-bound.
A possible problem with this sample code is that it could throw an exception if the user does not have the permissions to modify the item. Another drawback is that the performance would degrade siginficantly if you displayed a lot of items on the same page. Those are acceptable for demonstration purposes.
I am packing you a working project. You could use it as a starting point for your own customizations. Of course, you should change the paths in project.xml and the VS project to point to a valid location on your computer. You should also populate the bin directory of the web site. A detached database of mssql 2008r2 is included in the archive.
Kind regards,
Dido
the Telerik team
hello Telerik,
will this feature be fixed with the relaese of 14 april?
Thanks
Hello Paolo,
This has been scheduled for Q2.
Regards,And when it is scheduled for delivery Q2?
Hello, you gave me a complete system that is already working with the count, only that there were several inconsistencies with my system, instead of me you spend an entire project already working as you did, you could not pass me what changes should I do my project for the dll Telerik.Support.Samples spotting it and what must change in my project to run the count of the dll?
Makes a little tutorial for all of us, I'm sure that will not only meet me.
Already
Thanks
Hi Leandro,
After Q1 release we will spend some time creating a blog post or KB about this implementation. I see that Dido has attached entire project, so I do not think that there are issues with it.
Greetings,
Ivan Dimitrov
the Telerik team
Hi,
I am wondering if I can get some help with something similar.
I want the system to log in the database whenever a user has viewed a news item, by logging
the page title (e.g. News Item 1).
1 - I have created a simple User Control that does the database stuff in the Page_Load event.
// Get the currently logged in user.
var manager = UserManager.GetManager();
var currentUser = manager.GetUser(SecurityManager.GetCurrentUser().Identity.Name);
var m = PageManager.GetManager();
string itemTitle = m.GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key)).Page.Title.ToString();
// Establish a connection with the Database.
var dataConfig = Config.Get<
DataConfig
>();
string conStr = dataConfig.ConnectionStrings["SeflBriefing"].ConnectionString;
SqlConnection connection = new SqlConnection(conStr);
connection.Open();
try
// Try inserting into the database a new record of the current user and document.
SqlCommand command = new SqlCommand("dbo.spLogUserActivity", connection);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@firstname", SqlDbType.NVarChar, 50)).Value = currentUser.FirstName;
command.Parameters.Add(new SqlParameter("@lastname", SqlDbType.NVarChar, 50)).Value = currentUser.LastName;
command.Parameters.Add(new SqlParameter("@accessedwhat", SqlDbType.NVarChar, 255)).Value = itemTitle;
command.Parameters.Add(new SqlParameter("@accesstime", SqlDbType.DateTime2)).Value = DateTime.Now;
command.ExecuteNonQuery();
// finally, make sure the connection is closed.
finally if (connection.State != ConnectionState.Closed) connection.Close();
<%@ Control Language="C#" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="cpRR" TagName="ReaderRegister" Src="~/Controls/ReaderRegister.ascx"%>
<
telerik:RadListView
ID
=
"DetailsView"
ItemPlaceholderID
=
"ItemContainer"
AllowPaging
=
"False"
runat
=
"server"
EnableEmbeddedSkins
=
"false"
EnableEmbeddedBaseStylesheet
=
"false"
>
<
LayoutTemplate
>
<
div
class
=
"sfnewsDetails"
>
<
div
class
=
"sfnewsLinksWrp"
>
<
sf:MasterViewHyperLink
class
=
"sfnewsBack"
Font-Size
=
"20px"
Text="<%$ Resources:NewsResources, AllNews %>" runat="server" />
</
div
>
<
asp:PlaceHolder
ID
=
"ItemContainer"
runat
=
"server"
/>
</
div
>
</
LayoutTemplate
>
<
ItemTemplate
>
<
div
>
<
table
style
=
"width:100%;text-align:left;font-size:x-large;border-top:1px solid Black;border-bottom:1px solid Black;"
>
<
tr
>
<
td
colspan
=
"2"
style
=
"font-weight:bold;"
>Text</
td
>
</
tr
>
<
tr
>
<
td
style
=
"font-weight:bold;"
>Some Text</
td
>
<
td
>
<
table
style
=
"width:100%;"
>
<
tr
>
<
td
style
=
"text-align:right;font-weight:bold;"
>Staff Notice:</
td
>
<
td
style
=
"text-align:right;width:150px;"
>
<
sitefinity:TextField
runat
=
"server"
DisplayMode
=
"Read"
Value='<%# Eval("ReferenceCode")%>' />
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
<
tr
>
<
td
>Some more text here</
td
>
<
td
>
<
table
style
=
"width:100%;"
>
<
tr
>
<
td
style
=
"text-align:right;font-weight:bold;"
>Issued:</
td
>
<
td
style
=
"text-align:right;width:150px;"
>
<
sf:FieldListView
ID
=
"PublicationDate1"
runat
=
"server"
Format
=
"PublicationDate.ToLocal():dd-MM-yyyy"
/>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
</
table
>
</
div
>
<
h1
class
=
"sfnewsTitle"
>
<
asp:Literal
Text='<%# Eval("Title") %>' runat="server" />
</
h1
>
<
div
style
=
"font-size:medium;"
>
<
asp:Literal
ID
=
"Literal1"
Text='<%# Eval("Content") %>' runat="server" />
</
div
>
<
div
style
=
"font-size:large;"
>
<
asp:Literal
ID
=
"signatureLine"
Text
=
'_______________________________'
runat
=
"server"
/>
<
sitefinity:TextField
runat
=
"server"
DisplayMode
=
"Read"
Value='<%# Eval("Author")%>' />
<
sitefinity:TextField
runat
=
"server"
DisplayMode
=
"Read"
Value='<%# Eval("SourceName")%>' />
<
sf:FieldListView
ID
=
"PublicationDate"
runat
=
"server"
Format
=
"PublicationDate.ToLocal():dd MMM yyyy"
/>
<
cpRR:ReaderRegister
ID
=
"ucReaderRegister"
runat
=
"server"
/>
</
div
>
</
ItemTemplate
>
</
telerik:RadListView
>
Hi Andrei,
The single item page is a dynamic not existing in the SiteMap page. It is formatted based on the content item title. You should be able to get the news item title in DetailsView template
<asp:Literal Text='<%# Eval("Title") %>' runat="server" />
All the best,
Ivan Dimitrov
the Telerik team
Ivan,
Break it down for me. I am not sure what you mean.
Can I programmatically get the Title in my UserControl?
Give a code example based on the UserControl that I have submitted if possible.
Many thanks,
Andrei
Hi Andrei,
In your code you get the title in the same way
<
h1
class
=
"sfnewsTitle"
>
<
asp:Literal
Text='<%# Eval("Title") %>' runat="server" />
</
h1
>
Ivan,
Thank you very much. Its working now. I was being a bit silly.
Got it now, by placing the data fields in my own ASCX.
Many thanks,
Andrei