Tuesday, September 28, 2010
Binding a Custom Meta field to a Template in Sitefinity with a ASP.NET Usercontrol
To get the background about this issue please read this article in Sitefinity knowledge base.
The last section of the article suggests that you can use the following syntax to set the NavigateUrl property of the ASP.NET Hyperlink control with its Text property
<asp:HyperLink ID="PDFAttachment" runat="server" NavigateUrl='<%=this.Text %>'></asp:HyperLink>
However the above doesn’t work and <%= %> is rendered as plain text
After trying to figure this out for a while I found the following way to do this, the trick is to create a custom user control that implements ITextControl interface, like this
public partial class UserControls_PDFAttachmentDownload : System.Web.UI.UserControl, ITextControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string text;
public string Text
{
get
{
return this.text;
}
set
{
if (!string.IsNullOrEmpty(value))
{
this.showdownload.NavigateUrl = ResolveUrl(value);
}
}
}
}
The highlighted line above sets the NavigateUrl property from the Text value that is bound to the control.
The ASCX part of the user control simply has a ASP.NET Hyperlink control in it
<asp:HyperLink ID="showdownload" runat="server" Text="Download" />
To use this control just add a reference in the Template usercontrol that Sitefinity uses and your on your way.
<%@ Register TagName="Attachment" TagPrefix="PDF" Src="~/UserControls/PDFAttachmentDownload.ascx" %>
<div class="sf_singleNews">
....
<p>
<PDF:Attachment ID="PDFAttachment" runat="server" />
</p>
....
</div>
Hope this little trick helped you, let me know.
Labels: ASP.NET, Sitefinity
Sunday, October 18, 2009
Sitefinity CMS and "There were errors during services initialization, check the error log for details" error
I use Sitefinity and have been getting this error on some websites including zubairahmed.net.
This error is so weird that it appeared randomly and vanished on subsequent page load. Recently I found something that I believe was causing this error.
It appears that this error is linked to the available memory on the server hosting your website, so as soon as the server reaches its limit it flushes the cache and the web application throws the error, to work around that Sitefinity has put a web.config setting to cache the web pages in Database, surprisingly Sitefinity did not tell anyone about this hidden feature until I googled it (not that I didn't do it before) and found it here.
So all it required was changing this in web.config
<cachedependency mode="InMemory">
to
<cachedependency mode="InDatabase">
and so far no issues, hope it helps someone out there.
Labels: Cache, Sitefinity, Web.Config