November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
There are many ways to do things like this, it depends on what you're after and in which context you are using it.
You can use the LinkURL property of the PageData object, like so <%= CurrentPage.LinkURL %>
If you are using this in a PageList for example you can use the Container.CurrentPage for the page currently in the loop of the pagelist. And you'd have to use DataBinding syntax <%# Container.Currentpage.LinkURL %>
You should also think about encoding the attribute, and possibly about getting a friendly url. You could also use a asp:HyperLink control and set things from codebehind and you wouldn't have to care about encoding.
The easiest way is really to use the property control with the PageLink property, which will render a link with the page's name as text: <EPiServer:Property PropertyName="PageLink" runat="server" />
Hi Magnus!
Thanks for the Reply.
I am getting the value in the code behind like this way.
langLink.NavigateUrl = startPage["LanguageLink1"].ToString();
does the page type Property returns only pageid I want the pageLink but startPage["LanguageLink1"] gives me only the pageID.
If your property "LanguageLink1" is of the type "Page" then it will contain a reference to the page, and if you ToString it, it will return the ID.
To get the URL you first need to get the PageData object corresponding to the reference, and to get that you first have to get the reference in it's right form:
var pageLink = startPage["LanguageLink1"] as PageReference;
var page = DataFactory.Instance.GetPage(pageLink);
var url = page.LinkURL
You should of course add some error handling for when the property is not set etc.
Edit: Typo
Hi,
I am getting error in that
PageData startPage = DataFactory.Instance.GetPage(PageReference.StartPage);
var pageLink = startPage["LanguageLink1]" as PageReference;
var page = DataFactory.Instance.GetPage(pageLink);
var url = page.LinkURL
Cannot convert type string into episerver.core.pagerefrence.
No that shouldn't even compile. I made a typo but corrected it. Intellisense should even tell you that there's something seriously wrong with that line :)
You could also take a look at Itera:MultiProperty here you could render the code as this:
<Itera:Property runat="server" PropertyName="LanguageLink1">
<ItemTemplate><a href="{LanguageLink1.LinkURL}">{PageName}</a>
</Itera:Property>
This code will take the link from the page LanguageLink1 and the name of the currentpage.
Hello,
I am trying to show the "domainName.com/" + the Simple address for the page or friendly URL. Any ideas on how this could be possible for a pageTree?
// Simple adress
UriBuilder url = new UriBuilder(Settings.Instance.SiteUrl);
url.Path = CurrentPage["PageExternalURL"] as string;
string simpleAdress = url.Uri.AbsoluteUri;
And here's a handy extension method for friendly URL:
public static string ExternalURL(this PageData p, bool absoluteUrl)
{
UrlBuilder pageURLBuilder = new UrlBuilder(p.LinkURL);
Global.UrlRewriteProvider.ConvertToExternal(pageURLBuilder, p.PageLink, UTF8Encoding.UTF8);
string pageURL = pageURLBuilder.ToString();
if (absoluteUrl)
{
UriBuilder uriBuilder = new UriBuilder(Settings.Instance.SiteUrl);
uriBuilder.Path = pageURL;
return uriBuilder.Uri.AbsoluteUri;
}
return pageURL;
}
Hi have a page property and and pagelinkTitle property . I want to create a link like
<li><a href="#"><EPiServer:Property PropertyName="pagelinkTitle" runat="server" /></a></li>.
in my a href I want page Propert link. How do i write this property.