Click here to Skip to main content
15,917,875 members
Articles / Web Development / XHTML

ASP.NET PartialHyperLink Control

Rate me:
Please Sign up or sign in to vote.
4.84/5 (11 votes)
16 Jun 2009CPOL2 min read 40.5K   211   33   8
Introducing a small user control to simplify localization of literal text with contained hyperlinks
Image 1


Recently I has the need to localize some .ASPX files. I did that the standard way by using the "Generate local resources" tool bar button in the design view of an .ASPX file inside Visual Studio .NET 2008. 

Among others, I used the ASP.NET HyperLink control for hyperlinks and the ASP.NET Localize control for literal text.

What bothered me was that I often had a sentence with a hyperlink inside. E.g. "To get further information, please visit the support pages on our web site".

In the above example, I would have to split the sentence into two Localize controls and one HyperLink control. Too much effort for a lazy developer. In addition, the "split position" could vary among the different languages and the hyperlink also could be different in each language.

Introducing the PartialHyperLink Control

To make the described scenario more easy to handle, I wrote myself a light-weight control named "PartialHyperLink".

The control consists of one single .CS file that you can drop into your (web) project and use immediately.

It contains the following features:

  • Mimics the most common features of a standard HyperLink control
  • Has a NavigateUrl property that is localizable
  • Has a Text property that can include a start and an end placeholder to indicate where you want the clickable hyperlink

Using the Code

To use the control, simply put the "PartialHyperLink.cs" file into the "App_Code" folder of your web project.

Next, register the control on each .ASPX page you want to use it, by writing the following line at the top of the page:

<%@ Register Namespace="App_Code" TagPrefix="zeta" %>

Last, create an instance of the control by writing code similar to the following one:

    Text="This text that {0}includes a hyperlink{1} is inside a single control"
    meta:resourcekey="MyHyperLinkResource1" />

Use the placeholders "{0}" and "{1}" inside the Text property to mark the start and end of the clickable hyperlink.

That's all!

I've included a small example project to demonstrate how to use the control. If you open and run the project's solution, try switching the languages of your browser to see the different texts and hyperlinks that are loaded from the resources. I've included the languages English and German to give you an idea.


In this article, I have shown you a small user control that tries to simplify the task of translating literal texts with hyperlinks.

Maybe I am on a totally wrong path and there is already a built-in way of doing things that I implemented in my control. If yes, please tell me, I'd love to know!

In addition, if you have any questions, comments, bug reports or suggestions, please write them below in the comments section of this article. Thank you!


  • 2009-06-12
    • First published on The Code Project


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  

Comments and Discussions

GeneralMy vote of 4 Pin
Doug Domeny22-Jun-11 11:17
professionalDoug Domeny22-Jun-11 11:17 
Thanks for posting. This is a neat, simple solution to a really annoying problem. I made a couple of modifications. When VS generated the resx, the became , so I use a RegEx.Match to parse the text. Additionally, I derive from HyperLink to avoid having to copy all the properties.
GeneralAwesome Pin
jasonp1229-Dec-09 7:37
jasonp1229-Dec-09 7:37 
GeneralRe: Awesome Pin
Uwe Keim29-Dec-09 8:20
sitebuilderUwe Keim29-Dec-09 8:20 
GeneralNice idea, two small problems Pin
Richard Deeming16-Jun-09 3:26
mveRichard Deeming16-Jun-09 3:26 
GeneralRe: Nice idea, two small problems Pin
Uwe Keim16-Jun-09 3:35
sitebuilderUwe Keim16-Jun-09 3:35 
GeneralRe: Nice idea, two small problems Pin
Uwe Keim16-Jun-09 4:20
sitebuilderUwe Keim16-Jun-09 4:20 
GeneralGreat Idea Pin
Peter Lange13-Jun-09 9:52
Peter Lange13-Jun-09 9:52 
GeneralRe: Great Idea Pin
Uwe Keim13-Jun-09 9:54
sitebuilderUwe Keim13-Jun-09 9:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.