More in this section

Forums / Developing with Sitefinity / User control in blog markup

User control in blog markup

3 posts, 0 answered
  1. kevin croke
    kevin croke avatar
    6 posts
    11 Sep 2009
    14 Apr 2013
    Link to this post
    I've submitted a support request for this, but it has not been resolved. I figured I would give the community a stab at it.

    I want to add a user control to the blog widget. Instead of listing the author name, I have a custom field with a list of names. These names correspond with a specific page. I display this name and have some logic which creates a link to the author page.  This link is supposed to display on the publicly facing frontend. This link is generated by a usercontrol I am referencing in the widget markup on the backend. 

    I am editing the widget by going to /Sitefinity/Design/ControlTemplates and clicking on the Blog widget template. I added a reference to my control:
    <%@ Register Src="~/Controls/BlogAuthor.ascx" TagPrefix="uc1" TagName="BlogAuthor" %>

    And, in the widget, I added :
    <uc1:BlogAuthor runat="server" ID="BlogAuthor" AuthorName='<%# Eval("SelectedAuthor")%>' />

    The code of BlogAuthor.ascx (my control) is only being execute when I am logged into sitefinity. When I go to the blog page after logging off, the server code is not executed.

    Maybe I am missing something in the provided link, but I am not sure how to get the code behind to execute when I am not logged in.

    Here is the control referenced in the widget:
    <%@ Control Language="C#" AutoEventWireup="true"  %>
    <%@ Import Namespace="Telerik.Sitefinity" %>
    <%@ Import Namespace="Telerik.Sitefinity.Modules.Pages" %>
    <asp:HyperLink runat="server" ID="authorLink"></asp:HyperLink>
    <asp:Literal runat="server" ID="authorText"></asp:Literal>
    <script runat="server">
         public string AuthorName { get; set; }
        protected void Page_Load(object sender, EventArgs e)
            var bioPage = App.WorkWith().Pages().Where(x => x.Title.ToString().ToLower() == AuthorName.ToLower()).Get().FirstOrDefault();
            if (bioPage != null)
                authorLink.Visible = true;
                authorLink.NavigateUrl = bioPage.GetFullUrl();
                authorLink.Text = AuthorName;
                authorText.Visible = true;
                authorText.Text = AuthorName + "<!-- bio for author not created -->";

  2. Tim
    Tim avatar
    258 posts
    22 Jun 2011
    16 Apr 2013 in reply to kevin croke
    Link to this post

    Hmm, it may be bombing out because of the "App.WorkWith().Pages()" part. Once you log out, the code isn't running as a logged in user anymore and starts trying to access ALL pages (even back-end ones).

    Change that to:
  3. Pavel Benov
    Pavel Benov avatar
    341 posts
    14 Mar 2016
    17 Apr 2013
    Link to this post
    Hello Kevin,

    This will work if you map your custom template containing the user control declaration. Create an ascx file and place the markup for your blog list template. Then drop the Blogs list widget on a page and go to Edit->Advanced and find the layoutTemplatePath field. In it provide the relative path to your template. Locate the TemplateKey field, remove the Id string in it and save the changes. 

    Kind regards,
    Pavel Benov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
3 posts, 0 answered