User control in blog markup
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;
else
authorText.Visible = true;
authorText.Text = AuthorName + "
<!-- bio for author not created -->
";
</
script
>
Kevin,
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:
App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
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,