More in this section

Forums / Developing with Sitefinity / Add BlogPosts in TABstrip Control

Add BlogPosts in TABstrip Control

4 posts, 0 answered
  1. Pravat
    Pravat avatar
    59 posts
    Registered:
    22 Jun 2010
    31 Aug 2011
    Link to this post
    Hi Team,
                 I want to add two different blogpost in my custom Tabstrip control. Please help how to add.

    My custom control ascx is

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomTabStrip.ascx.cs" Inherits="Sitefinity_CustomControls_CustomTabStrip" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <div id="tabs">
        <telerik:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="RadMultiPage1"
            SelectedIndex="0" EnableEmbeddedSkins="false" Skin="Telerikbase">
            <Tabs>
                <telerik:RadTab Text="Blog" runat="server" PageViewID="RadPageView1" Selected="True">
                </telerik:RadTab>
                <telerik:RadTab Text="Resources" runat="server" PageViewID="RadPageView2">
                </telerik:RadTab>
            </Tabs>
        </telerik:RadTabStrip>
        <telerik:RadMultiPage ID="RadMultiPage1" CssClass="multiPageClass" runat="server"
            SelectedIndex="0">
              
            <telerik:RadPageView ID="RadPageView1" runat="server">
                <div class="item">
                    <asp:PlaceHolder ID="List1" runat="server"></asp:PlaceHolder>
                </div>
            </telerik:RadPageView>
             
            <telerik:RadPageView ID="RadPageView2" runat="server">
                <div class="item">
                    <asp:PlaceHolder ID="List2" runat="server"></asp:PlaceHolder>
                </div>
            </telerik:RadPageView>
              
        </telerik:RadMultiPage>
    </div>

    and code behind code is

    protected void Page_Load(object sender, EventArgs e)
        {
      
            if (Page.Master.Controls[3].FindControl("CPHRightContent") != null)
            {
                for (int i = Page.Master.Controls[3].FindControl("CPHRightContent").Controls.Count - 1; i >= 0; i--)
                {
                    if (Page.Master.Controls[3].FindControl("CPHRightContent").Controls[i].GetType() == typeof(BlogPostView))
                    {
                        BlogPostView blogCtrl = (BlogPostView)Page.Master.Controls[3].FindControl("CPHRightContent").Controls[i];
                          
                        if (i == 2)
                        {
                            List1.Controls.Add(blogCtrl);
                        }
                        else if (i == 3)
                        {
                            List2.Controls.Add(blogCtrl);
                        }
      
                    }
                }
            }
      
        }

    i am getting following error.

    The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.


    Please help me.

  2. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    01 Sep 2011
    Link to this post
    Hello Pravat,

     Try adding the controls directly to the PageView, like this:

    RadPageView1.Controls.Add(blogCtrl);
    If that doesn't solve the issue, feel free to get back to me, providing some more information about the Master Page you are using and the page that you are dropping the control on.

    Best wishes,
    Svetoslav Petsov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. Pravat
    Pravat avatar
    59 posts
    Registered:
    22 Jun 2010
    05 Sep 2011
    Link to this post
    hi Svetoslav Petsov ,
                                     Thanks for providing info, but still i am getting same error.

    I am droping blogpost control before tabstrip control on home page. Please help.


    Thanks & Regards,
    Pravat sharma
  4. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    08 Sep 2011
    Link to this post
    Hi Pravat,

     Sorry for the delay. The issue here is that you are getting one of the controls that Sitefinity is rendering and you try to modify it (e.g. put it in the Tab Strip) which cannot be done. What you can do is create a copy of this control and add the copy to the Tab Strip (this way you are not interfering with the objects created by Sitefinity, but you are creating your own object, which is a copy of the BlogView control and you have full control over it). Here's a sample code that finds the control in the control on the page in a simpliest way, copies it into another object and then adds the new control to the PageView:

    var test = Page.Master.FindControl("CPHRightContent");
                foreach (var item in test.Controls)
                {
                     
                    if (item.GetType().Name == "BlogPostView")
                    {
                        BlogPostView blogControl = new BlogPostView();
                        blogControl.CopyBaseAttributes(item as BlogPostView);
                        
                        RadPageView1.Controls.Add(blogControl);
                         
                    }
                }
    Kind regards,
    Svetoslav Petsov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

4 posts, 0 answered