+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Multipage long news articles automatically

Multipage long news articles automatically

3 posts, 0 answered
  1. Nischal Jain
    Nischal Jain avatar
    8 posts
    Registered:
    19 Apr 2010
    16 Feb 2011
    Link to this post
    Hello,

    Good Morning. I have long news articles and I need to multipage them automatically  whenever an article has more than 500 words (for example if one article has 700 words - first page should have 500 and second 200) without changing  main URL  of the page.

    I have the basic idea of modifying the listpagedetails.ascx template and I would like to modify the content portion ..
    i.e.
    <asp:Literal ID="content" runat="server"></asp:Literal>

    that limits article content to certain range and do the paging. Is there a way to create a custom class that I can use in listpagedtails.ascx  for paging? I have the code for paging -  but I am trying to know how I can include this into the listpagedetails.ascx content section. Please,advise.

    I am using Sitefinity 3.7.2096.  

    Thanks for your help in advance.

    Regards,
    Nischal


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Feb 2011
    Link to this post
    Hi Nischal Jain,

    It would be better if you just Ajaxify the content and show the first 500 chars and then the other on some button click. You can take a look at this demo. You can also use jQuery with some effects like fadeIn



    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Nischal Jain
    Nischal Jain avatar
    8 posts
    Registered:
    19 Apr 2010
    23 Feb 2011
    Link to this post
    Hello Ivan,

    Thanks for your help.  I do not know this is the best way but I solved the paging issue.

    The solution is as below:


    1. In ListPageDetails.ascx : set  content literal to "false" and add one more literal.
    <asp:Literal ID="content" runat="server" Visible="false" ></asp:Literal>
    <asp:Literal ID="content1" runat="server" ></asp:Literal>

    2. Add code-behind to ListPageDetails.ascx

    3. Add below code to code behind :

    protected void Page_Load(object sender, EventArgs e)
           {
                              
               string Article = content.Text; // get the article content
               string Output;
               string ThisPage = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]; // gets current page
               string PageNo;
               PageNo = HttpContext.Current.Request.QueryString["Page"];
               string[] strValues = new string[1000];
               int i = 0;
               int wordCount = 0;
               string[] strsplit = Article.Split(' '); //split the article into string array
     
               
               int x=300; // number of words per page
     
               string strNav = "";
     
               foreach( string s in strsplit)
               {
                 wordCount++;
               }
     
               //set the total number of pages by dividing total wordcount with required number of words per page
               double divd = (double)wordCount / x;
               int idivd = wordCount/ x;
       
               int totalPages = 0;
     
               if (divd <= 1.0)
               {
                   totalPages = 1;
               }
               else
               {
                   totalPages = idivd + 1;
               }
     
                
               // set start and end word numbers
               int _start = 0;
               int _end = x;
                
               for (i = 0; i < totalPages; i++)
               {
                   strValues[i] = getStrings(_start, _end, strsplit);     // returns string for each page           
                   _start = _start + x;
                   _end = _end + x;
               }
     
                
            // if there is more than one page
               if (wordCount > x)
               {
                   int Counter = 1;
                   int pagenumber = 1;
     
                   if (PageNo != null)
                   {
                       pagenumber = System.Convert.ToInt32(PageNo);
                   }
     
                   // set the string for the page
                   Output = strValues[pagenumber - 1];
                   Output += "<p>";
     
                  
     
                   while (Counter <= totalPages)
                   {
                                          
                       if (Counter == pagenumber)
                       {
                           if (Counter == 1) //if first page
                           {
                               strNav = "  " + "<a href=\"" + ThisPage + "?Page=" + (Counter + 1).ToString() + "\"> Next </a> ";
                               Output += strNav;
                           }
                           else if (Counter == totalPages) //if last page
                           {
                               strNav = "  " + "<a href=\"" + ThisPage + "?Page=" + (Counter - 1).ToString() + "\"> Prev </a> ";
                               Output += strNav;
                           }
                           else
                           {                           
                                strNav = "  " + "<a href=\"" + ThisPage + "?Page=" + (Counter - 1).ToString() + "\"> Prev </a> ";
                                strNav += "  " + "<a href=\"" + ThisPage + "?Page=" + (Counter + 1).ToString() + "\"> Next </a> ";
                               Output += strNav;
                           }
                       }
     
                       Counter++;
                   }
                   Output += "</p>";
               }
     
               else
               {
                   Output = Article;
               }
               content1.Text= Output + "<br/>";
               
    }
          
     
        
       public string getStrings(int _start, int _end, string[] strval)
           {
               int i = 0;
               string sp = "";
     
               // concatenate and return strings for each page
               foreach (string s in strval)
               {
                   if (i >= _start && i <= _end)
                   {
                       sp += s + " ";                   
                   }
                   i++; 
               }                      
               return sp;
           }

    This will do.

    Thanks,
    Nischal


Register for webinar
3 posts, 0 answered