MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

How to create another blog container ?  (Mono Support )

Viewed 6261 time(s), 9 post(s) 12/31/2012 6:57:11 PMby super
super

super

12/31/2012 6:57:11 PM
I want to create blog container separately from default one specifically for home page. Right now I have blog container on my home page but whatever settings I do for this reflects on the blog section because both are sharing this.

I want to create separate blogcontainer and blog post list for homepage so that I can have different blog posts per page numbers for homepage and blog section separately.

For example, I have all blog posts on my homepage..but I do not want to display 10 blog posts on homepage but 10 blog posts in blog section (going from menu tab) makes more sense because it is blog section. That's why I want to have different blog containers and blogpost list... how to do that ?

Right now I copied blogpostlist (in gallary) and pasted in same folder by creating a copy and changed to Codebehind="BlogContainerHome.ascx.cs" %> because I renamed the copy container to "BlogContainerHome"

But is this correct way ? I doubt it because without source code it might throw errors ? I do see underline under "BlogContainerHome" because it doesn't exists right now ?
This content has not been rated yet. 
6018 Reputation 709 Total posts
denis

denis

1/3/2013 6:45:40 PM
You can create multiple parts in that fashion, but their codebehind should still point to the original .cs file. The better way to do it is to create a separate codebehind for such parts, but than inherit from the original class in the codebehind of the copied part.
However, I am not sure that I understand the rest of the question. If you would only like to change a few simple properties (like the number of blog posts), you should take the easier route and just place the instance of the original part on the page (either via the code block, or via drag and drop). 
This content has not been rated yet. 
7207 Reputation 956 Total posts
super

super

1/3/2013 9:59:46 PM
Denis,

Thanks for the reply and Sorry for the confusion, let me explain my situation:

1) I want to have "All Blog posts" blog container on the homepage so that all users will see the latest blog posts (from all irrespective of coming from any blog list - that's why I said "All blog post).

2) At the same time I DO NOT want to display 10 blog posts in the blog container on the homepage because you know homepage should not include so many blog posts, homepage should be little bit of everything so on homepage I want latest 2 or 3 blog posts.

3) But when any user go to "Blog" page by clicking on "Blog" from the main menu links - In that case I need 10 blog posts (NOT 2 or 3).

4) Dragging the blog container on home page uses the same code logically that is being used in blog section (when going from menu tabs to blog page / section)

5) The problem is in BlogPostList .ascx (in gallery - in code)  If I change this:

<mono:Pager runat="server" ID="pager" PageSize="10" NumericButtonCount="5" AllowCustomPaging="true"
        AutoPaging="false">

to

<mono:Pager runat="server" ID="pager" PageSize="2" NumericButtonCount="5" AllowCustomPaging="true"
        AutoPaging="false">

The homepage does display only 2 blog posts but when I go to "Blog" section from the main menu , (i.e. monox.mono-software.com/blog/posts/) - In this section also only 2 blog posts per page are being displayed.


Solution:

I came up with an idea that in visual studio, I created 2 new .ascx (exact copies of BlogPostList.ascx & BlogContainer.ascx) and named them to BlogPostListHome.ascx & BlogContainerHome.ascx


This is the code of my these 2 new .ascx in which I have changed the path to point to new .ascx

BlogContainerHome.ascx
<%@ Control
    Language="C#"
    AutoEventWireup="True"
    Inherits="MonoSoftware.MonoX.ModuleGallery.Blog.BlogContainer"
    Codebehind="BlogContainer.ascx.cs" %>
 
<%@ Register TagPrefix="MonoX" TagName="BlogPostList" Src="/MonoX/ModuleGallery/Blog/BlogPostListHome.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="BlogPostEdit" Src="/MonoX/ModuleGallery/Blog/BlogPostEdit.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="BlogPostView" Src="/MonoX/ModuleGallery/Blog/BlogPostView.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="BlogSettings" Src="/MonoX/ModuleGallery/Blog/BlogSettings.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="BlogComments" Src="/MonoX/ModuleGallery/Blog/BlogCommentsList.ascx" %>
 
<div class="blog">
    <MonoX:BlogPostList ID="blogPostList" runat="server" RssEnabled="true" ParseCustomTags="Description" />
    <MonoX:BlogPostEdit ID="blogPostEdit" runat="server" />
    <MonoX:BlogPostView ID="blogPostView" runat="server" />
    <MonoX:BlogSettings ID="blogSettings" runat="server" />
    <MonoX:BlogComments ID="blogComments" runat="server" />
</div>

BlogPostListHome.ascx
<%@ Control
    Language="C#"
    AutoEventWireup="true"
    Inherits="MonoSoftware.MonoX.ModuleGallery.Blog.BlogPostList"
    CodeBehind="BlogPostList.ascx.cs" %>
 
<%@ Register Namespace="MonoSoftware.Web.Pager" Assembly="MonoSoftware.Web.Pager" TagPrefix="mono" %>
<%@ Register Src="/MonoX/controls/SyntaxHighlighter/SyntaxHighlighter.ascx" TagPrefix="mono" TagName="SyntaxHighlighter" %>
 
<mono:SyntaxHighlighter ID="syntaxHighlighter" runat="server" />
<asp:Panel ID="pnlContainer" runat="server">
    <div class="blog-top-section clearfix" runat="server" id="lbHeader">
        <div class="blog-info">
            <asp:Literal runat="server" ID="ltlH1Open"><h1></asp:Literal><asp:Literal ID="ltlBlogName" runat="server"></asp:Literal><asp:Literal runat="server" ID="ltlH1Close"></h1></asp:Literal>
            <asp:Literal ID="ltlBlogDescription" runat="server"></asp:Literal>
        </div>
        <div class="main-options">
            <ul class="first" id="panFilter" runat="server">
                <li title="<%= MonoSoftware.MonoX.Resources.BlogResources.BlogPostList_Filter_Title %>">
                    <asp:HyperLink ID="lnkCurrent" runat="server" ></asp:HyperLink>
                    <ul class="level0">
                        <li><asp:HyperLink ID="lnkFirst" runat="server" ></asp:HyperLink></li>
                        <li><asp:HyperLink ID="lnkSecond" runat="server" ></asp:HyperLink></li>
                    </ul>
                </li>
            </ul>
            <asp:HyperLink runat="server" ID="lnkComments"></asp:HyperLink>
            <asp:HyperLink runat="server" ID="lnkSettings"></asp:HyperLink>
            <asp:HyperLink runat="server" ID="lnkAddNew" CssClass="float-right"></asp:HyperLink>
        </div>
    </div
    <asp:Literal runat="server" ID="ltlHeaderSpace"><br /></asp:Literal
    <asp:ListView ID="lvItems" runat="server">
        <LayoutTemplate>
            <div class="clearfix">
                <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
            </div>
        </LayoutTemplate>
        <ItemTemplate>
        </ItemTemplate>
    </asp:ListView>
    <asp:Label runat="server" ID="lblNoData" CssClass="empty-list"></asp:Label>
    <mono:Pager runat="server" ID="pager" PageSize="2" NumericButtonCount="5" AllowCustomPaging="true"
        AutoPaging="false">
        <PagerTemplate>
        </PagerTemplate>
    </mono:Pager>
</asp:Panel>



Is this the correct approach ?

When I login as admin and click on "Change the look and functionality of the page" (in homepage) and select web parts and in blog tab I do see 2 blogcontainers and the second one works fine with 2 posts per page.

Why I am getting these errors ?
Warning 1   File 'BlogPostList.ascx.cs' was not found.
 
Warning 4   File 'BlogContainer.ascx.cs' was not found





This content has not been rated yet. 
6018 Reputation 709 Total posts
super

super

1/4/2013 4:54:02 PM
denis ? any update here ?
This content has not been rated yet. 
6018 Reputation 709 Total posts
denis

denis

1/4/2013 5:01:27 PM
Here is an example from another project:

NewBlogPosts.ascx
<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="NewBlogPosts.ascx.cs" Inherits=CustomProject.WebParts.Blog.NewBlogPosts" %>
<%@ Register Assembly="MonoX" Namespace="MonoSoftware.MonoX" TagPrefix="portal" %>
<%@ Register TagPrefix="MonoX" TagName="Search" Src="/MonoX/ModuleGallery/MonoXSearch.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="BlogPostList" Src="/MonoX/ModuleGallery/Blog/BlogPostList.ascx" %>
<%@ Import Namespace="JobsMarket.Resources" %>   
 <div class="blogs">
    <h2 class="title-padding">Blogs</h2>
    <MonoX:BlogPostList ID="ctlBlogPostList" runat="server" RewritePageTitle="false" RetainBreaksInDescription="false" RssEnabled="true" IsHeaderVisible="false" MaxDescriptionChars="80" PageSize="5" MaxTitleChars="50" PagingEnabled="false" />
</div>


NewBlogPosts.ascx.cs
sing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MonoSoftware.MonoX;
using MonoSoftware.MonoX.Utilities;
using MonoSoftware.Core;
 
namespace CustomProject.WebParts.Blog
{
    public partial class NewBlogPosts : BaseAutoRegisterPart
    {
 
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            ctlBlogPostList.Template = "BlogListHomePage";
            ctlBlogPostList.UrlSingleBlogPost = UrlUtility.RewritePagePath(ctlBlogPostList.UrlSingleBlogPost, RewrittenPaths.BlogPost.DefaultPage);
        }
    }
}

This content has not been rated yet. 
7207 Reputation 956 Total posts
super

super

1/4/2013 5:41:55 PM
could you please comment on my approach ? is it correct ? if no how I should go about it ?
This content has not been rated yet. 
6018 Reputation 709 Total posts
denis

denis

1/4/2013 5:45:50 PM
No, it isn't. It makes no sense to change the code of a web part just to be able to control the behavior that is already exposed via original part properties (I'm talking about the PageSize property here). You should take advantage of the existing functionality whenever you can.
This content has not been rated yet. 
7207 Reputation 956 Total posts
super

super

1/4/2013 6:42:06 PM
I have not changed the code of original webpart, you can see above that I just have duplicated the original webpart and changed the page size in the 2nd copy of webpart....it is working with warnings that I posted above.. If my way is 100% incorrect, so what would you recommend me to do when I want 2 to 3 last / latest blog posts on homepage but in blog post section, I want around 10 blog posts per page ?
This content has not been rated yet. 
6018 Reputation 709 Total posts
denis

denis

1/4/2013 7:57:09 PM
I would recommend to use the code from my earlier answer for a home page part with 2 or 3 posts, so the standard blog post list can remain unchanged.
This content has not been rated yet. 
7207 Reputation 956 Total posts