Rendering URLs
Render Page URLs and Media URLs in User Control functions
To render a page URL or a media URL in a C1 CMS compliant way, you can use /page(...) and /media(...):
.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RenderUrls.ascx.cs" Inherits="C1Function" %> <asp:HyperLink runat="server" ID="funnyPage" ><%= PageUrl.Data.Title %></asp:HyperLink> <asp:Image ID="fancyImage" runat="server" />
.ascx.cs
using System;
using Composite.Functions;
using Composite.Data;
using Composite.Data.Types;
public partial class C1Function : Composite.AspNet.UserControlFunction
{
public override string FunctionDescription
{
get
{
return "A demo function that shows a page link and an image.";
}
}
public DataReference<IPage> PageUrl { get; set; }
public DataReference<IMediaFile> ImageSource { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
funnyPage.NavigateUrl = String.Format("/page({0})", PageUrl.Data.Id);
fancyImage.ImageUrl = String.Format("/media({0})", ImageSource.Data.Id);
}
}With page URLs you can also use SitemapNavigator to render URLs.
.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RenderUrlsWithSitemapNavigator.ascx.cs" Inherits="C1Function" %> <asp:HyperLink runat="server" ID="funnyPage" ><%= PageUrl.Data.Title %></asp:HyperLink>
.ascx.cs
using System;
using Composite.Functions;
using Composite.Data;
using Composite.Data.Types;
public partial class C1Function : Composite.AspNet.UserControlFunction
{
public override string FunctionDescription
{
get
{
return "A demo function that shows a page link using SitemapNavigator.";
}
}
public DataReference<IPage> PageUrl { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
using (var connection = new DataConnection()){
funnyPage.NavigateUrl = connection.SitemapNavigator.GetPageNodeById(PageUrl.Data.Id).Url;
}
}
} Download the sample

