I have some text which is loaded from a resource file. Ordinarily, to get dynamic content I would use:
string.Format(GetLocalResourceObject("SomeText"), PhoneNumberAsString)
I want to do the same with a link, only the link needs to be application relative as I have URLs like mysite.com/page.aspx
and mysite.com/fr/page.aspx
.
I normally use an <asp:HyperLink />
tag to create the links as I can then just put a squiggle at the start NavigateUrl="~/page.aspx"
. However, I don't know of a way to get a dynamic HyperLink to appear as a string without adding it as a control to something.
Simply writing ToString()
outputs System.Web.UI.WebControls.HyperLink.
.
How do I get a link out of a resource file and make it into a hyperlink using ASP.NET Webforms?
UPDATE
With some help from the answers I now have the following code on my page:
<p><%= string.Format(GetGlobalResourceObject("Resource", "MoreThan1000Users").ToString(), ResolveUrl("~/contact-us.aspx")) %></p>
and in my resource file I have:
If you would like more than 1000 users please <a href="{0}">call our sales team</a>.
Does this seem like good practice or is there another way to achieve what I'm doing? I don't know if I should be happy or not that there is HTML inside the resource file.