More in this section

Forums / General Discussions / why viewscount posts not working?

why viewscount posts not working?

26 posts, 0 answered
  1. Leandro
    Leandro avatar
    4 posts
    Registered:
    03 Nov 2010
    31 Jan 2011
    Link to this post
    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.
  2. renato
    renato avatar
    72 posts
    Registered:
    07 Jan 2011
    01 Feb 2011
    Link to this post
    I also have that doubt, would help me a lot!
  3. Petya
    Petya avatar
    123 posts
    Registered:
    30 May 2017
    02 Feb 2011
    Link to this post
    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,
    Petya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Ilaria
    Ilaria avatar
    25 posts
    Registered:
    20 Jan 2011
    15 Feb 2011
    Link to this post
    Hello!
    can you please tell me if it will be addressed with an internal build or have I to wait till SP1?

    thanks
    Ilaria
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 Feb 2011
    Link to this post
    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
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Paolo
    Paolo avatar
    147 posts
    Registered:
    11 Jun 2009
    16 Feb 2011
    Link to this post
    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
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Feb 2011
    Link to this post
    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
  8. Leandro
    Leandro avatar
    4 posts
    Registered:
    03 Nov 2010
    17 Feb 2011
    Link to this post
    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
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    18 Feb 2011
    Link to this post
    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
  10. renato
    renato avatar
    72 posts
    Registered:
    07 Jan 2011
    18 Feb 2011
    Link to this post
    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?
  11. Ilaria
    Ilaria avatar
    25 posts
    Registered:
    20 Jan 2011
    21 Feb 2011
    Link to this post
    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?
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Feb 2011
    Link to this post
    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
  13. Ilaria
    Ilaria avatar
    25 posts
    Registered:
    20 Jan 2011
    21 Feb 2011
    Link to this post
    Can you please me give me an example about it?
  14. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    21 Feb 2011
    Link to this post
    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);
                }
            }
        }
    }

    This code should be flexible enough to handle any kind of content item. There are few interesting things about this code:
    • It demonstrates how to implement data-context-aware control. You do so by overriding OnDataBinding, and retrieving the data-bound-context by using the Sitefinity Control method extension GetDataItemContainer. It is registered in Telerik.Sitefinity.Web, so you have to include the namespace in order to use it. Your data item will be in the DataItem property.
    • The relatively new AnyContent fluent API is used. It is an abstraction that should work on any Content-derived model, as long as it meets certain conditions (e.g. ManagerTypeAttribute).
    • Since on the public side we see only live items (published), we are guaranteed to have a live item. We skip the content lifecycle, (e.g. no CheckOut and CheckInAndPublish calls). If you are curious, they would not work, since we have not yet implemented document counting (which is much more complex than this oversimplified example), and it is not copied over lifecycle states. Finally, we SaveChanges.
    • An overly simple "render" is implemented.

    Once you have put your class in an assembly and referenced it from your web project, you will have to choose which templates to use the control. I chose the List of documents for direct download widget template, and made the following changes:

    <%@ 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>

    Of course, you should change your change your Register directive to whatever your setup is. As I said before, this control is data-bound, and, therefore, inserted inside the repeater. Since it outputs a number or nothing, you can customize its output to whatever you like.

    The final step for this example to work is to create and publish a page with DownloadList on it. Make sure you choose the template we've modified (edit->settings->type:list).

    Regards,
    Dido
    the Telerik team
  15. Ilaria
    Ilaria avatar
    25 posts
    Registered:
    20 Jan 2011
    22 Feb 2011
    Link to this post
    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;
  16. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    14 Mar 2011
    Link to this post
    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
  17. Paolo
    Paolo avatar
    147 posts
    Registered:
    11 Jun 2009
    11 Apr 2011
    Link to this post
    hello Telerik,
    will this feature be fixed with the relaese of 14 april?
    Thanks
  18. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Apr 2011
    Link to this post
    Hello Paolo,

    This has been scheduled for Q2.

    Regards,
    Georgi
    the Telerik team

  19. Leandro
    Leandro avatar
    4 posts
    Registered:
    03 Nov 2010
    12 Apr 2011
    Link to this post
    And when it is scheduled for delivery Q2?
  20. Leandro
    Leandro avatar
    4 posts
    Registered:
    03 Nov 2010
    12 Apr 2011
    Link to this post
    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
  21. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Apr 2011
    Link to this post
    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

  22. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    16 May 2011
    Link to this post
    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(); } }

    2 - Then I have registered the User Control in the single news item template.
    <%@ 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>

    But all it registers in the database is the page title of the page on which the news list is placed.
    Why and what do I do to get the title of the actual news item in the database.?

    Many thanks,
    Andrei


  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 May 2011
    Link to this post
    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
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  24. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    17 May 2011
    Link to this post
    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
  25. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 May 2011
    Link to this post
    Hi Andrei,

    In your code you get the title in the same way

    <h1 class="sfnewsTitle">
                <asp:Literal Text='<%# Eval("Title") %>' runat="server" />
            </h1>


    This returns the time as per your request "Why and what do I do to get the title of the actual news"

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  26. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    17 May 2011
    Link to this post
    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
26 posts, 0 answered