Create Blog Using Code
I need to load a blog control and configure it using code
Hello jaime,
Thank you for using our services.
Bellow is a sample code snippet which you can use to add a posts view control on the page:
PageManager pageManager = PageManager.GetManager();//get page to which we are going to add hte controlvar page = pageManager.GetPageDataList().Where(t => t.Title == "Home").SingleOrDefault();//get a placeholders lists, we are going to use this so that we define the placeholder to which we are going to add the controlList<PageControl> controls = page.Controls.Where(c=> c.IsLayoutControl == true).Cast<PageControl>().ToList();PageDraft editPage = pageManager.EditPage(page.Id, false);//instantiate a new BlogPostsView controlBlogPostView postsView = new BlogPostView();//create a page control from it and add it to the pagevar pageControl = pageManager.CreateControl<PageDraftControl>(postsView,controls[0].PlaceHolder);editPage.Controls.Add(pageControl);pageManager.PublishPageDraft(editPage,true);pageManager.SaveChanges();BlogPostView p = new BlogPostView();p.MasterViewDefinition.ItemsPerPage = 5;p.MasterViewDefinition.TemplatePath = "PathToExternalTemplate";There are no controls in the collection
Hi jaime,
The error is saying that the page does not contain layout controls. I have prepared this sample to work for a page which does not use a master page for template, but rather a template built from the UI, containing layout controls. If your page's template derives from a master page you can use the content place holder's IDs when you create the page control.
All the best,
Radoslav Georgiev
the Telerik team
Hello,
I developed a single item display control for blog. How can i replace my control with SF's default single item display control?
Thank You
Roops
Hello Roopesh,
You can register your control through the web.config <toolboxControls> section and then use it on your page.
Kind regards,
Ivan Dimitrov
the Telerik team