Add BlogPosts in TABstrip Control

Posted by Community Admin on 04-Aug-2018 10:00

Add BlogPosts in TABstrip Control

All Replies

Posted by Community Admin on 31-Aug-2011 00:00

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.

Posted by Community Admin on 01-Sep-2011 00:00

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

Posted by Community Admin on 05-Sep-2011 00:00

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

Posted by Community Admin on 08-Sep-2011 00:00

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

This thread is closed