As I mentioned in my previous post, one of the more common controls I put on my web sites is a links page. I wanted the links page to be somewhat dynamic, easily updateable, without having to update the ASPX page. I wanted to be able to create a simple place where I could store my data, and even, have it sync across multiple sites if I wanted. I haven't implemented this part yet, but it is in the works.
So, I created a user control that reads the links from an XML file. You specify the XML file in the user control line so it knows where to get it's data from, and it then puts the data on the page.
<%@ Register Src="LinkDisplay.ascx" TagName="LinkDisplay" TagPrefix="uc1" %>
<uc1:LinkDisplay DataFile="~/App_Data/references.xml" ID="LinkDisplay1" runat="server" />
For this one, the code was pretty simple.
public string DataFile = "";
protected void Page_Load(object sender, EventArgs e)
if (DataFile != "")
xmlLinks.DataFile = DataFile;
And the ASPX was just as easy
<asp:DataList DataSourceID="xmlLinks" ID="DataList1" runat="server">
<asp:HyperLink Target="_blank" ID="HyperLink1" NavigateUrl='<%# XPath("url") %>'
runat="server" Text='<%# XPath("title") %>'></asp:HyperLink>
<asp:Label ID="lblDesc" CssClass="LinkLabel" runat="server" Text='<%# XPath("description") %>' />
<asp:XmlDataSource ID="xmlLinks" runat="server" />
You can see it in use at http://www.bbpphoto.com/links.aspx and http://www.nocommonground.com/blogSamples/links.aspx. The one on BBPPhoto is actually several of the user controls on the same page, all pointing to different XML files, thus providing different categories.
You can download the whole sample here: http://www.nocommonground.com/blogSamples/links.zip